.class在Java中是什么意思?

.class在Java中是什么意思?

问题描述:

.class 是什么意思在Java?例如,如果我创建了一个名为 Print 的类。 Print.class 返回?

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

c $ c> .class 在类名后面,它引用 Class 对象。

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

例如,如果您的类是打印(建议类名以大写字母开头)那么 Print.class 是在运行时表示类 Print 的对象。它是由打印的任何(直接)实例的 getClass()方法返回的相同对象。 / p>

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());