下面的代码片段会在 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/