首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Java反射-多维浮点数组类

Java反射-多维浮点数组类
EN

Stack Overflow用户
提问于 2010-07-01 03:26:16
回答 2查看 472关注 0票数 0

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

代码语言:javascript
运行
复制
[rawtypes] found raw type: org.openide.nodes.PropertySupport.Reflection
  missing type parameters for generic class org.openide.nodes.PropertySupport.Reflection<T>
代码语言:javascript
运行
复制
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()返回一个值为float[][][]类的Class对象。如何在设计时指定这一点并避免此警告?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-07-01 03:51:15

你工作太辛苦了。在制作PropertySupport.Reflection时不要使用dataStore.getFloat3DClass(),使用float[][][].class就可以了。运行库也会为您缓存该值。

票数 1
EN

Stack Overflow用户

发布于 2010-07-01 03:40:39

您需要为属性和PropertySupport指定类型参数。您可以使用<?>,也可以使用<float[][][]>。如果使用后一种方法,Class.forName将不可避免地对结果进行未经检查的强制转换

代码语言:javascript
运行
复制
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;
        }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3152689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档