.class 在 Java 中是什么意思? [英] What does .class mean in 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?
推荐答案
当你在类名后面写 .class
时,它引用了类字面量 -java.lang.Class
对象,表示关于给定类的信息.
When you write .class
after a class name, it references the class literal -
java.lang.Class
object that represents information about given class.
例如,如果您的类是 Print
,则 Print.class
是一个在运行时表示 Print
类的对象.它与 Print
的任何(直接)实例的 getClass()
方法返回的对象相同.
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());
这篇关于.class 在 Java 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文