How does this Java statement compile without warnings?
Class<Integer> x = int.class;
even though
Integer.class != int.class
Edit: Putting it a different way, it seems as though Integer.class and int.class have nothing in common (see comments below), so why does it make sense for this assignment to be possible?
After a whole lot of searching, I came across this little snippet in the JLS, section 15.8.2 Class Literals:
The spec doesn’t explain why this is so, instead of
Class<?>for example. I have also been unable to find any evidence that this is related to either generics or autoboxing.Integeris a first-class object whereasintis a primitive type, and most methods ofClasssuch asisInstance,isAssignableFromandcastwhich operate onObjects are invalid in the context ofint.class. Consequently, I do not see any reason why the type ofint.classisClass<Integer>.