Bug 80123 - Class<A<B>> literal problem
Summary: Class<A<B>> literal problem
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-03 11:59 EST by Constantine Plotnikov CLA
Modified: 2004-12-09 09:11 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Constantine Plotnikov CLA 2004-12-03 11:59:24 EST
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); 
	}
}
Comment 1 Jerome Lanneluc CLA 2004-12-09 09:11:35 EST
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.