Name: rmT116609 Date: 05/03/2004
A DESCRIPTION OF THE REQUEST :
If A is a Type parameter, nothing in JSR-14 spec (spec 8) forbids me from using the expresson
But if I do so, it generates a compiler Error.
Sometimes I need to return a Class object of a parameterized type. An example is a parameterized implementation of a TableModel. It uses a separate Column<ColType> instance for each column, but when writing the getColumnClass() method, the expression ColType.class generates this compiler error:
cannot select from a type variable
The .class member is sufficiently universal that it should be allowed.
I don't see any other way to return the Class object of a parameterized type. (Any other way would satisfy me, but I won't always have an instance of the type, so I can't call its getClass() method.)
Note: The class java.lang.Object has been modified so that the getClass()
method returns an object of type
Class<? extends Object>
I don't know if this helps me get a class object of a parameterized type, but
I found no reference to the ? symbol in the "specification of proposed
language modifiations" in spec8.pdf. So I have no idea what it means.
EXPECTED VERSUS ACTUAL BEHAVIOR :
The expression A.class should be legal, even when A is a parameterized type. It should resolve to the actual class invoked by the constructor.
The expression A.class generates a compiler error.
---------- BEGIN SOURCE ----------
/* Compile this source code to see the error message. */
public class ClassBug <CB>
public Class getBugClass()
---------- END SOURCE ----------
(Incident Review ID: 260837)