Community
Participate
Working Groups
I'm using eclipse-SDK-I20041201-win32.zip. I'm not sure if this situation is bug or not because javac has the same problem. Possibly it is actually a bug in Java language. It is not possible to specify a literal class constant when template class is expected. The neither of tests below work. I have encountered this situation in a comlex scenario with templates that is structurally similar to TestClass3, so it is real life problem. Current workaround is to avoid using Class<T> at all, but it removes type checking. --------- test/TestClass.java ---------------- package test; import java.util.Set; class TestClass { final Class<Set<Integer>> val = Set.class; } --------- test/TestClass2.java ------------------ package test; import java.util.Set; class TestClass2 { final Class<Set<Integer>> val = Set<Integer>.class; } ----------test/TestClass3 --------- package test; import java.util.LinkedList; class TestClass3<T> { final Class<T> i; TestClass3(Class<T> c) { i = c; } public static void main(String args[]) { TestClass<LinkedList<String>> test1 = new TestClass<LinkedList<String>>(LinkedList.class); } }
Indeed the Java Language Specification (section 15.8.2) says that it is a compile time error if the named type of a class literal is a parameterized type. We (and javac) behave according to the spec.