class在java中,.class在Java中是什么意思?

What does .class mean in Java? For example, if I created a class called Print. What does Print.class return?

解决方案

When you write .class after a class name, it references the Class object that represents the given class.

For example, if your class is Print (it is recommended that class name begin with an uppercase letter), 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());

What does .class mean in Java? For example, if I created a class called Print. What does Print.class return? 解决方案 When you write .class after a class name, it references the Class object that represents the given class. For example, if your class is Print (it is recommended that class name begin with an uppercase letter), 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());
经验分享 程序员 微信小程序 职场和发展