ITeye博客

Java Class 的翻译

as619864232 · 2012-05-04 14:49 · Java · Hibernate · Translate · 编程语言 · Java · 翻译 · class · Markdown

java.lang

Class Class<T>

java.lang.Object 

            java.lang.Class<T> 

Type Parameters:

T - the type of the class modeled by this Class object. For example, the type of String.class is Class<String>. Use Class<?> if the class being modeled is unknown.

All Implemented Interfaces: 

Serializable, AnnotatedElement, GenericDeclaration, Type 

--------------------------------------------------------------------------------

public final class Class<T>

extends Object

implements Serializable, GenericDeclaration, Type, AnnotatedElement

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. 

The following example uses a Class object to print the class name of an object: 

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. 

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. See Section 15.8.2 of The Java? Language Specification. For example: 

System.out.println("The name of class Foo is: "+Foo.class.getName());

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。