Hi,
When i build a class that implements IScriptObject, Eclipse ( Version: 3.5.0 ) gives a warning :
Class is a raw type. References to generic type Class should be parameterized
the warning points to
public Class[] getAllReturnedTypes() {
return null;
}
I now it is just a warning, but Ilike to know how to “repair” it.
regards,
hans
Hi Hans,
this message is generated by Eclipse depending on your compiler source level and target and the degree of “sensitivity” of your compiler set in your preferences.
Basically with Java 1.5 (and 1.6 even more) you are supposed to clearly state what your arrays or collections are going to contain, this is java 5 generics to you!
Now if you don’t like that (because “raw” collections and arrays are still legal java after all), you can modify the sensitivity of the warnings in your Eclipse preferences (globally or per project), see above where to set the “usage of raw type” warning to “ignore” :
[attachment=0]EclipseErrorsWarning.gif[/attachment]
Hope this helps,
Hi Patrick,
Thanks, that did the trick.
Regards,
Hans
Perhaps Servoy should be starting to improve their code quality by setting the type properly in these generics…I know I tried once in the jasperreports plugin but they were removed again! ![Sad :(]()
Quite,
but in that case Tom, I don’t think you can do much.
Consider that this method is used to return an array of ANY type of classes, for example:
public Class[] getAllReturnedTypes() {
return new Class[] {ClassOfType1.class, WhateverClass2.class, MyThirdClassType.class};
}
So, generics are useless here and would potentially lead to write the following method as such (if enforced):
public Class<Object>[] getAllReturnedTypes() {
return new Class<Object>[] {ClassOfType1.class, WhateverClass2.class, MyThirdClassType.class};
}
Which is plain stupid really!
It is actually better. But that is not a discussion for this forum.
public Class<?> getAllReturnedTypes() {
return new Class {ClassOfType1.class, WhateverClass2.class, MyThirdClassType.class};
}
The wildcard <?> is far better for readability than the .
I prefer to have types explicit so I can get compile type errors out of the way and not have to deal with errors at run time.
jcompagner:
public Class<?> getAllReturnedTypes() {
return new Class {ClassOfType1.class, WhateverClass2.class, MyThirdClassType.class};
}
You are right Johan,
I forgot about the wildcard, just goes to show how I don’t use them all the time ![Wink ;-)]()
- That’s what happens when you have to maintain code targeted for 1.4 anyway!
But Tom,
the wildcard in that case is just a shortcut to say to the compiler: just ignore generics here, I’m going to put Anything I want in my array anyway! So what kind of compile time error are you going to get here? Whatever you put in that array will compile. So I still don’t see the advantage for that particular method, but as you said, perhaps not a discussion for this forum ![Smile :)]()