Java Reflection - 多维 float 组类

标签 java reflection

下面的代码片段会在 NetBeans 6.9 中导致此警告。

[rawtypes] found raw type: org.openide.nodes.PropertySupport.Reflection
  missing type parameters for generic class org.openide.nodes.PropertySupport.Reflection<T>
Property dataProp = new PropertySupport.Reflection(t, dataStore.getFloat3DClass(),
                        workingData);

/**
 * Gets the Class object associated with the primitive 3d float array (i.e., float[][][]).
 *
 * @return  the Class object.
 */
public Class<?> getFloat3DClass()
{
    if (class3DFloat == null)
    {
       try
       {
           class3DFloat = Class.forName("[[[F");
       }
       catch (ClassNotFoundException ex)
       {
           Exceptions.printStackTrace(ex);
       }
    }

    return class3DFloat;
}

在运行时getFloat3DClass()返回一个Class对象,其值为类float[][][]。如何在设计时指定这一点并避免出现此警告?

最佳答案

您需要为 Property 和 PropertySupport 指定类型参数。您可以使用 <?>或者你可以使用 <float[][][]> 。如果您执行后者,将不可避免地对 Class.forName 的结果进行未经检查的转换。 :

Property<float[][][]> dataProp =
    new PropertySupport<float[][][]>.Reflection(t, dataStore.getFloat3DClass(),
                                                workingData);

...

public Class<float[][][]> getFloat3DClass() {
    ...
    if (class3DFloat == null)
    {
        try
        {
            @SuppressWarnings("unchecked")
            Class<float[][][]> tmp = (Class<float[][][]>)Class.forName("[[[F");
            class3DFloat = tmp;
        }

关于Java Reflection - 多维 float 组类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3152689/

相关文章:

java - 寻求有关 JVM 随机崩溃的帮助

java - 查找现在通过的@Ignore'd 测试

java - 服务器发起的客户端-服务器通信

java - 无法将加密格式从 Java 复制到 PHP

java - 如何检查 java.lang.reflect.Method 返回类型是 Collection?

android - 防止反射 - android

java - 重写类实例的方法?

java - 处理不同类型对象之间交互的设计模式

asp.net - 获取 ASP.NET MVC 站点在文件系统中的路径

c# - 从 roslyn 中的符号获取类型