当前位置: 技术问答>java相关
java.lang.Class包有什么作用?
来源: 互联网 发布时间:2015-03-21
本文导语: | Class类是封装了类和对象的属性特征的类,它包含解释一个Java类的信息。Class类的实例表示一个运行Java应用程序的类和接口的信息。Class对象能表示在程序运行的类,系统的任一对象都是一些Class类的实例。 你...
|
Class类是封装了类和对象的属性特征的类,它包含解释一个Java类的信息。Class类的实例表示一个运行Java应用程序的类和接口的信息。Class对象能表示在程序运行的类,系统的任一对象都是一些Class类的实例。
你可以去看jdk的帮助文档。
你可以去看jdk的帮助文档。
|
java.lang
Class Class
java.lang.Object
|
+--java.lang.Class
All Implemented Interfaces:
Serializable
--------------------------------------------------------------------------------
public final class Class
extends Object
implements Serializable
Instances of the class Class represent classes and interfaces in a running Java application. 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());
}
Since:
JDK1.0
See Also:
ClassLoader.defineClass(byte[], int, int), Serialized Form
Class Class
java.lang.Object
|
+--java.lang.Class
All Implemented Interfaces:
Serializable
--------------------------------------------------------------------------------
public final class Class
extends Object
implements Serializable
Instances of the class Class represent classes and interfaces in a running Java application. 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());
}
Since:
JDK1.0
See Also:
ClassLoader.defineClass(byte[], int, int), Serialized Form