基于Java class对象说明、Java 静态变量声明和赋值说明(详解)
短信预约 -IT技能 免费直播动态提醒
先看下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
基于Java class对象说明、Java 静态变量声明和赋值说明(详解)
下载Word文档到电脑,方便收藏和打印~
下载Word文档
猜你喜欢
基于Java class对象说明、Java 静态变量声明和赋值说明(详解)
先看下JDK中的说明:java.lang.Object java.lang.Class Instances of the class Class represent classes and interfaces in a runn
2023-05-31