Class类(在java.lang包中,Instances of the class Classrepresent classes and interfaces in a running Javaapplication):
在Java中,每个class都有一个相应的Class对象。也就是说,当我们编写一个类,编译完成后,在生成的.class文件中,就会产生一个Class对象,用于表示这个类的类型信息
public final Class<?> getClass ()
Added in
API level 1
Returns the unique instance of Class
that represents this object's class. Note that getClass()
is a special case in that it actually returns Class<? extends Foo>
where Foo
is the erasure of the type of the expression getClass()
was called upon.
As an example, the following code actually compiles, although one might think it shouldn't:
List l = new ArrayList();
Class<? extends List> c = l.getClass();
Returns
- this object's
Class
instance.