Hi
( This is the first time to post something to the newsgroup so please
don't be harsh )
This is not exactly a problem, I'm just trying to figure out some things
in JDK 5. I have the following method:
public boolean addClass( Class c ) {
if( !c.isAnnotationPresent( SomeAnnotation.class ) )
throw new InvalidJdbcObjectException("Missing annotation for type: "+c);
...
}
... now, in the second line a warning is indicated: "The method
isAnnotationPresent(Class) belongs to the raw type Class. References to
generic type Class<T> should be parameterized"...
Is there a way of avoiding this warning through a standard procedur
(withoud compiler params, just code workaround or something).
Thank you.
Tor Iver Wilhelmsen - 05 Apr 2005 22:40 GMT
> if( !c.isAnnotationPresent( SomeAnnotation.class ) )
Your use is consistent with Sun's example at
http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
despite the JLS saying that Foo.class is of the ungeneric type
"Class".
Fred - 06 Apr 2005 14:40 GMT
So why not parameterize the parameter?
public boolean addClass( Class<? extends Object>c ) would be somewhat
flexible. Or if you know the type of class that will be used as an
argument, that'd be even more appropriate (i.e. Class<this_type> c ).
That's just off the cuff, though, which is to say I've not tried to
compile either.
-Fred