I accidentally found that this works:
Class<?> a;
a = int.class;
System.out.println(a); // int
a = Integer.class;
System.out.println(a); // class java.lang.Integer
What does it really mean / do for primitives?
I tried and neither List<int>
nor List<int.class>
works (yeah, I know I have to use Integer). Also, obviously, I can't invoke getClass()
on primitives, so it's useless for type checking of any sort.
In what situation would I use int.class
and why is it even present in the language?
void.class
! In the spec, here.