When you write .class
after a class name, it references the class literal -
java.lang.Class
object that represents information about given class.
For example, if your class is Print
, then Print.class
is an object that represents the class Print
on runtime. It is the same object that is returned by the getClass()
method of any (direct) instance of Print
.
Print myPrint = new Print();
System.out.println(Print.class.getName());
System.out.println(myPrint.getClass().getName());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…