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.
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());
}
public final class Method extends AccessibleObject implements GenericDeclaration, Member
Method
provides(提供) information about, and access to, a single method on a class or interface. The reflected method may be a class method or an instance method (including an abstract method).
A Method
permits(许可,允许) widening (扩展) conversions to occur when matching(匹配) the actual(实际) parameters to invoke(调用) with the underlying(底层) method's formal parameters(形参), but it throws an IllegalArgumentException
if a narrowing(缩小,收缩) conversion would occur.