Quentin- By definition, the members of a RAW type (a generic type without type parameters) are the ERASED members of the class. This is not affected by whether or not the signature of the member uses the type parameters of the class. Making it behave as you seem to expect would significantly complicate the type system. If you don't want the erasing to happen, then use the wildcard <?> version of the generic class.
Generally speaking, you shouldn't expect generics to "work" in the presence of raw types. It is better not to mix raw and generic code. Cheers, Neal On Sat, Sep 26, 2009 at 12:51 PM, Quintin Beukes <quin...@last.za.net>wrote: > Hey, > > When you have parameterized methods in a parameterized class, and you > don't use the parameters of the class, then the parameters of all it's > methods are also ignored, even when not related. Is there any specific > reason why it was done like this? If not, I would like to implement > it, as I don't see why you have to loose the method's generic ability > when you don't use that of the class. > > Take for instance, this example: > class AnnotatedMethod > { > public <M> M annotatedMethod(M obj) > { > return obj; > } > } > > class AnnotatedClass<C> > { > public <M> M annotatedMethod(M obj) > { > return obj; > } > } > > public class AnnotationDemo > { > public static void main(String[] args) throws Exception > { > AnnotatedMethod method = new AnnotatedMethod(); > String s1 = method.annotatedMethod("string"); > > AnnotatedClass<?> clazzWorking = new AnnotatedClass(); > String s2 = clazzWorking.annotatedMethod("string"); > > AnnotatedClass clazzNotWorking = new AnnotatedClass(); > String s3 = clazzNotWorking.annotatedMethod("string"); > } > } > > Quintin Beukes >