什么是 Java 中的类字面量? [英] What is a class literal in Java?
本文介绍了什么是 Java 中的类字面量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自 Java 教程:
最后,还有一种特殊的字面量,称为类字面量,由类型名称并附加.class
"构成;例如,String.class
.这是指代表类型本身的对象(Class
类型).
Finally, there's also a special kind of literal called a class literal, formed by taking a type name and appending "
.class
"; for example,String.class
. This refers to the object (of typeClass
) that represents the type itself.
这个文字可以分配给什么类型的变量?
To what type of variable can this literal be assigned to?
如果可能,请举一个小例子.
Please give a small example if possible.
推荐答案
Class<String> c = String.class;
查看 Javadoc for java.lang.Class
看看你可以用这些小家伙中的一个做什么 - 主要与反射有关
Check out the Javadoc for java.lang.Class
to see what you can do with one of these little guys - mostly related to reflection
这篇关于什么是 Java 中的类字面量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文