Community
Participate
Working Groups
I'm using eclipse-SDK-3.1M5a-win32.zip. I have encountered strange problem with using generics. When generic class has a generic method then the method loses genericity if generic class is used as non generic. In sample below m1 does not compile and m2 compiles. Note: Javac has the same problem. So I'm not sure if this is a bug or feature. The following are shown in Problems view: Severity Description Resource In Folder Location Creation 1 Type safety: The method willBe(Class) belongs to the raw type Test.B. References to generic type Test.B<C> should be parameterized Test.java test/test line 16 2 Type mismatch: cannot convert from Test.I1 to Test.I2 Test.java test/test line 16 --------- begin of test/Test.java -------------- package test; public class Test { static class B<C> { public <T extends I1> T willBe(Class<T> c) { return (T)null; } } interface I1 { } interface I2 extends I1 { } public static void m1(String[] args) { B b = new B(); I2 v = b.willBe(I2.class); } public static void m2(String[] args) { B<Void> b = new B<Void>(); I2 v = b.willBe(I2.class); } } ----------- end of test/Test.java ------------
Only static generic methods remain generic when used on a raw type.
Please refer to JLS[3] 4.8. Closing