先看下JDK中的说明:
java.lang.Object java.lang.Class<T> Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.The following example uses a Class object to print the class name of an object: void printClassName(Object obj) { System.out.println("The class of " + obj + " is " + obj.getClass().getName()); } It is also possible to get the Class object for a named type (or for void) using a class literal. System.out.println("The name of class Foo is: "+Foo.class.getName());在一个运行着的JAVA应用中,类的任何实例都可以用Class对象来指代,Class可以指代所有的类和接口。枚举属于类,注解属于接口,均可以用Class指代。每个数组均属于反射的Class对象,数组中的每个元素和维度也同样拥有Class对象。Java基本类型(boolean, byte, char, short, int, long, float, and double)以及关键字void也都可以用Class指代。Class类不存在构造函数,当类被加载过程中由JVM通过调用类加载器中的defineClass方法自动构造。下面的例子是将一个对象通过Class对象打印出类名。 void printClassName(Object obj) { System.out.println("The class of " + obj + " is " + obj.getClass().getName()); }通过class关键字指定类型也是可以得到Class对象的 System.out.println("The name of class Foo is: "+Foo.class.getName());
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
软考中级精品资料免费领
- 历年真题答案解析
- 备考技巧名师总结
- 高频考点精准押题
- 资料下载
- 历年真题
193.9 KB下载数260
191.63 KB下载数245
143.91 KB下载数1139
183.71 KB下载数640
644.84 KB下载数2752
相关文章
发现更多好内容猜你喜欢
AI推送时光机 咦!没有更多了?去看看其它编程学习网 内容吧