Class Class<T>
- java.lang.Object
-
- java.lang.Class<T>
-
-
Type Parameters:
-
T- the type of the class modeled by thisClassobject. For example, the type ofString.classisClass<String>. UseClass<?>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, AnnotatedElementInstances of the classClassrepresent(表示) classes and interfaces in a running Java application. An enum is akind(种类) of class and an annotation(注释) is a kind of interface. Every array alsobelongs(属于) to a class that isreflected(反射) as aClassobject that isshared(共享) by all arrays with the same element type and number ofdimensions(大小). Theprimitive(基本) Java types (boolean,byte,char,short,int,long,float, anddouble), and the keyword(关键字)voidare also represented asClassobjects.Classhas no public cons tructor(构造方法). InsteadClassobjects are constructedautomatically(自动的) by the JavaVirtual Machine(虚拟机) as classes are loaded and by calls to thedefineClassmethod in the class loader.The following example uses a
Classobject to print the class name of an object:void printClassName(Object obj) { System.out.println("The class of " + obj + " is " + obj.getClass().getName()); }It is also possible(可能的) to get the
Classobject for anamed(指定的) type (or for void) using a class literal(字面的). See Section 15.8.2 ofThe Java™ LanguageSpecification(规范). For example:System.out.println("The name of class Foo is: "+Foo.class.getName());
java.lang.reflectClass Method
- java.lang.Object
-
- java.lang.reflect.AccessibleObject
-
- java.lang.reflect.Method
-
-
All Implemented Interfaces:
- AnnotatedElement, GenericDeclaration, Member
public final class Method extends AccessibleObject implements GenericDeclaration, Member
AMethodprovides(提供) 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
Methodpermits(允许) widening(扩展) conversions tooccur(发生) whenmatching(匹配) the actual(实际的) parameters to invoke with theunderlying(基础) method'sformal(形式的) parameters, but it throws anIllegalArgumentExceptionif anarrowing(收缩) conversion would occur.
-
本文详细介绍了Java中Class与Method类的功能与使用方法。Class类用于表示运行中的Java应用程序中的类和接口,提供了获取类名、构造Class对象的方法。Method类则提供了关于类或接口上单一方法的信息及访问权限。
1455

被折叠的 条评论
为什么被折叠?



