Generics - <A extends Annotation> getAnnotation
Hello. I'm using reflection to obtain some properties of entity classes in EJB 3.0.
There two methods that cougth my attention given the way in which the complirer treats them:
Class.<A extends Annotation> A getAnnotation(Class<A> annotationClass)
and
Method.<T extends Annotation> T getAnnotation(Class<T> annotationClass)
Looking at their signatures, I figure they should work in the same way, however, this is what actually happens:
EmbeddedId embId = method.getAnnotation(EmbeddedId.class);
-> no complaining here. works great.
Table tableAnnotation = (Table) entityClass.getAnnotation(Table.class);
->Type safety: The method getAnnotation(Class) belongs to the raw type Class. References to generic type Class<T> should be parameterized
Note that I has to use a cast in the Class' getAnnotation, or otherwise it would not compile.
Please explain me this behaviour and tell me how to get rid of that warning.
Thanks in advance,
Hugo Oliveira
hugom.oliveira.ext@siemens.com

