---
title: "Java Class 的翻译"
author: "as619864232"
date: "2012-05-04T14:49:23Z"
tags: ["Java", "class", "翻译"]
categories: ["编程语言"]
slug: "java-class"
draft: false
lastmod: "2012-05-04T15:35:19Z"
id: 1511306
url: "https://ears.iteye.com/blog/1511306"
---

java.lang

**Class Class&lt;T&gt;**

java.lang.Object 

            java.lang.Class&lt;T&gt; 

Type Parameters:

T - the type of the class modeled by this Class object. For example, the type of String.class is Class&lt;String&gt;. Use Class&lt;?&gt; if the class being modeled is unknown.

All Implemented Interfaces: 

Serializable, AnnotatedElement, GenericDeclaration, Type 

\--------------------------------------------------------------------------------

public final class Class&lt;T&gt;

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());