In Java you can write the following code:
Class<?> stringClass = String.class;
The run-time will assign a reference to a Class instance represents the type java.lang.String class.
My questions are:
- Is it guaranteed by the JVM that a Class instance is a singleton per Java type?
- If the answer to #1 is true - when the Class instance is being created? (- calling
getClass()
orType.class
or maybe when the Class loader is loading a Java type at the first time.) - What happens under the hood when invoking
Type.class
. I am asking since there is no static member calledclass
in the code of-course.