views:

45

answers:

3

The code snippet below causes this warning in 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;
}

At runtime getFloat3DClass() returns a Class object whose value is class float[][][]. How do I specify this at design time and avoid this warning?

+2  A: 

You need to specify a type parameter for Property and for PropertySupport. You could either use <?> or you could use <float[][][]>. If you do the latter there will be an unavoidable unchecked cast of the result from 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;
        }
Laurence Gonsalves
You're circumnavigating the world to get to next door. At the language level, `float[][][]` *is* a class name and supports the `class` pseudo-field.
Donal Fellows
That's true. I assumed that the code he provided was just to illustrate the problem he was having in his real code.
Laurence Gonsalves
A: 

The problem is that you are instantiating PropertySupport.Reflection without specifying type.

Do it like this:

new PropertySupport.Reflection<float[][][]>(..)
Bozho
+1  A: 

You're working too hard. Don't use dataStore.getFloat3DClass() when you're making a PropertySupport.Reflection, use float[][][].class and it will work. And the value will be cached by the runtime for you too.

Donal Fellows