From what I know, there is a feature in Java called a class literal, which, applied to a type name, causes JVM to produce an object of type Class<?>
, which is a generic class. More specifically, the following construct is correct:
Class<type> o = type.class;
where type
is a name of any type available for use.
What confuses me is a combination of two facts. The first, that the class literal may be used with the primitive types as well, i.e. a construct like int.class
is perfectly valid. And the second, that one's not allowed to use primitive types to parameterize generics, which means that a construct like Class<int> c;
won't compile.
Given all the above, what type is used as the Class
type parameter in the Class<?> c = int.class;
statement?
Thanks!
It's simply a
Class<Integer>
.Even if you used the primitive type Class representation, it's still a
Class<Integer>
: