分享
 
 
 

java.lang.Class翻译

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

[/url] [url=file:///F:/资料/文字资料/j2sdk-1_4_2-doc/docs/api/overview-summary.html]Overview

Package

Class

Use

Tree

Deprecated

Index

Help

JavaTM 2 Platform

Std. Ed. v1.4.2

PREV CLASS NEXT CLASS

FRAMES NO FRAMES All Classes

SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

java.lang

Class Classjava.lang.Object

java.lang.Class

All Implemented Interfaces: Serializable public final class Class extends Object implements SerializableInstances of the class Class represent classes and interfaces in a running Java application. 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的实例表示当前运行的Java应用程序中的类和接口。每个数组也属于一个class,被映射为 一个Class对象,被所有有着相同元素和数字大小的数组共享。简单Java类型(boolean、byte、char、short、 int、long、float、double)和关键字void也能表示为Class对象。

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. Class没有公共的构造函数。当类被加载后或者通过ClassLoader的defineClass方法调用时,由Java虚拟机 自动构造出Class对象。

The following example uses a Class object to print the class name of an object: 以下的例子使用Class对象打印某个对象的class名称:

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 (JLS Section 15.8.2). For example: 对于命名类型(或者void)使用class属性来获得Class对象也是可以的。(JLS Section 15.8.2)例如:

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

Since: JDK1.0 See Also: ,]ClassLoader.defineClass(byte[], int, int), Serialized FormMethod Summary

boolean

desiredAssertionStatus()

Returns the assertion status that would be assigned to this class if it were to be initialized at the time this method is invoked. 如果该类初始化时调用该方法,返回指定给该类的断言状态。

static Class

forName(String className)

Returns the Class object associated with the class or interface with the given string name.返回指定字符串名称的类或接口的Class对象。

static Class

forName(String name, boolean initialize, ClassLoader loader)

Returns the Class object associated with the class or interface with the given string name, using the given class loader. 使用指定的类加载器返回指定字符串名称的类或接口的Class对象。

Class[]

getClasses()

Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object. 返回一Class对象数组,表示该Class对象表示的类中的所有作为成员的公共类和接口。

ClassLoader

getClassLoader()

Returns the class loader for the class. 返回该类的类加载器。

Class

getComponentType()

Returns the Class representing the component type of an array. 返回一Class对象,表示数组的成员类型。

Constructor

)]getConstructor(Class[] parameterTypes)

Returns a Constructor object that reflects the specified public constructor of the class represented by this Class object. 返回一Constructor对象,映射该Class对象表示的类的指定公共构造函数。

Constructor[]

getConstructors()

Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. 返回一Constructor对象数组,映射该Class对象表示的类中所有公共构造函数。

Class[]

getDeclaredClasses()

Returns an array of Class objects reflecting all the classes and interfaces declared as members of the class represented by this Class object. 返回一Class对象的数组,映射该Class对象表示的类中作为成员声明的所有类和接口。

Constructor

)]getDeclaredConstructor(Class[] parameterTypes)

Returns a Constructor object that reflects the specified constructor of the class or interface represented by this Class object. 返回一Constructor对象,映射该Class对象表示的类或接口中的指定构造函数。

Constructor[]

getDeclaredConstructors()

Returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object. 返回一Constructor对象数组,映射该Class对象表示的类中的所有声明的构造函数。

Field

getDeclaredField(String name)

Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object. 返回一Field对象,映射该Class对象表示的类或接口中的指定声明域。

Field[]

getDeclaredFields()

Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. 返回一Field对象数组,映射该Class对象表示的类或接口中声明的所有域。

Method

getDeclaredMethod(String name, Class[] parameterTypes)

Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object. 返回一Method对象,映射该Class对象表示的类或接口中的指定声明方法。

Method[]

getDeclaredMethods()

Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object. 返回一Method对象数组,映射该Class对象表示的类或接口中声明的所有方法。

Class

getDeclaringClass()

If the class or interface represented by this Class object is a member of another class, returns the Class object representing the class in which it was declared. 如果该Class对象表示的类或接口是另一个类的成员,返回表示该类的Class对象。

Field

getField(String name)

Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object. 返回一Field对象,映射该Class对象表示的类或接口中的指定公共成员域。

Field[]

getFields()

Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. 返回一Field对象数组,映射该Class对象表示的类或接口中的所有可访问公共域。

Class[]

getInterfaces()

Determines the interfaces implemented by the class or interface represented by this object. 返回该对象表示的类或接口所实现的接口。

Method

getMethod(String name, Class[] parameterTypes)

Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object. 返回一Method对象,映射该Class对象表示的类或接口中的指定公共成员方法。

Method[]

getMethods()

Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces. 返回一Method对象数组,映射该Class对象表示的类或接口中声明的所有公共成员方法,包括类或接口中声明的和从父类或父接口中继承的。

int

getModifiers()

Returns the Java language modifiers for this class or interface, encoded in an integer. 返回该类或接口的Java语言修饰符,编码成整数型。

String

getName()

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.以String形式返回该Class表示的实体(类、接口、简单类型或void)的名称。

Package

getPackage()

Gets the package for this class. 获得该类的包。

ProtectionDomain

getProtectionDomain()

Returns the ProtectionDomain of this class. 返回该类的ProtectionDomain。

URL

getResource(String name)

Finds a resource with a given name. 通过指定名称查找资源。

InputStream

getResourceAsStream(String name)

Finds a resource with a given name. 通过指定名称查找资源。

Object[]

getSigners()

Gets the signers of this class. 获得该类的签名者。

Class

getSuperclass()

Returns the Class representing the superclass of the entity (class, interface, primitive type or void) represented by this Class. 返回该Class表示的实体(类、接口、简单类型或void)的父类的Class对象。

boolean

isArray()

Determines if this Class object represents an array class. 确定该Class对象是否表示数组类。

boolean

isAssignableFrom(Class cls)

Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter. 确定该Class对象表示的类或接口是否和指定的Class变量表示的类或接口相同,或者是其的父类、父接口。

boolean

isInstance(Object obj)

Determines if the specified Object is assignment-compatible with the object represented by this Class. 确定指定的Object是否可赋值给该Class表示的对象。

boolean

isInterface()

Determines if the specified Class object represents an interface type. 确定指定的Class对象是否表示接口类型。

boolean

isPrimitive()

Determines if the specified Class object represents a primitive type. 确定指定的Class对象是否表示简单类型。

Object

newInstance()

Creates a new instance of the class represented by this Class object.创建一个新的该Class对象表示的类的实例。

String

toString()

Converts the object to a string. 将该对象转换成字符串。

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Method Detail

toStringpublic String toString()

Converts the object to a string. The string representation is the string "class" or "interface", followed by a space, and then by the fully qualified name of the class in the format returned by getName. If this Class object represents a primitive type, this method returns the name of the primitive type. If this Class object represents void this method returns "void". 将该对象转换成字符串。字符串形式为“class”或“interface”,后跟一个空格,然后是类的全名,格式和getName的返回值相同。 如果Class对象表示简单类型,方法返回简单类型的名称。如果Class对象表示void,方法返回void。

Overrides: toString in class ObjectReturns: a string representation of this class object. 该对象的字符串形式。forNamepublic static Class forName(String className)

throws ClassNotFoundException

Returns the Class object associated with the class or interface with the given string name. Invoking this method is equivalent to: 返回指定字符串名称的类或接口的Class对象。调用该方法相当于: Class.forName(className, true, currentLoader)

where currentLoader denotes the defining class loader of the current class. 这里currentLoader定义当前类的类加载器。 For example, the following code fragment returns the runtime Class descriptor for the class named java.lang.Thread: 例如,以下代码片断返回名称为java.lang.Thread的类的运行时Class描述符:

Class t = Class.forName("java.lang.Thread")

A call to forName("X") causes the class named X to be initialized. forName("X")的调用会造成X类被初始化。

Parameters: className - the fully qualified name of the desired class. 期望类的全名。 Returns: the Class object for the class with the specified name. 指定名称类的Class对象。 Throws: LinkageError - if the linkage fails 如果链接失败时抛出 ExceptionInInitializerError - if the initialization provoked by this method fails 此方法激发的初始化过程失败时抛出 ClassNotFoundException - if the class cannot be located 该类不能被定位时抛出forNamepublic static Class forName(String name,

boolean initialize,

ClassLoader loader)

throws ClassNotFoundException

Returns the Class object associated with the class or interface with the given string name, using the given class loader. Given the fully qualified name for a class or interface (in the same format returned by getName) this method attempts to locate, load, and link the class or interface. The specified class loader is used to load the class or interface. If the parameter loader is null, the class is loaded through the bootstrap class loader. The class is initialized only if the initialize parameter is true and if it has not been initialized earlier. 使用指定的类加载器返回指定字符串名称的类或接口的Class对象。给出类或接口的全名(格式和getName的返回值相同),方法尝试定位、加载和链接该类和接口。指定的类加载器用于加载类和接口。如果参数loader是null,类的加载通过引导类加载器进行,只有 initialize参数为true,并且还没有被初始化时才初始化。 If name denotes a primitive type or void, an attempt will be made to locate a user-defined class in the unnamed package whose name is name. Therefore, this method cannot be used to obtain any of the Class objects representing primitive types or void. 如果name表示简单类型或void,将尝试在未命名的包中定位名称是name的用户定义类。因此该方法不能用于获取简单类型或void的Class对象。

If name denotes an array class, the component type of the array class is loaded but not initialized. 如果name表示数组类,数组类的成员类型被加载但不会被初始化。

For example, in an instance method the expression: 例如,表达式

Class.forName("Foo")

is equivalent to: 相当于 Class.forName("Foo", true, this.getClass().getClassLoader())

Note that this method throws errors related to loading, linking or initializing as specified in Sections 12.2, 12.3 and 12.4 of The Java Language Specification. Note that this method does not check whether the requested class is accessible to its caller. 注意该方法抛出与加载、链接或初始化相关的错误详见Java语言规范12.2、12.3和12.4节。注意该方法不会检查请求类是否能访问它的调用者。 If the loader is null, and a security manager is present, and the caller's class loader is not null, then this method calls the security manager's checkPermission method with a RuntimePermission("getClassLoader") permission to ensure it's ok to access the bootstrap class loader. 如果loader不为null,安全管理其存在,调用者的类加载器不为null,那么该方法使用RuntimePermission("getClassLoader") 许可调用安全管理器的checkPermission方法以确认是否可以访问引导类加载器。

Parameters: name - fully qualified name of the desired class 期望类的全名 initialize - whether the class must be initialized 该类是否必须初始化 loader - class loader from which the class must be loaded 必须加载该类的类加载器 Returns: class object representing the desired class 表示期望类的class对象 Throws: LinkageError - if the linkage fails 链接失败时抛出 ExceptionInInitializerError - if the initialization provoked by this method fails 由此方法激发的初始化过程失败时抛出 ClassNotFoundException - if the class cannot be located by the specified class loader 如果该类不能通过指定类加载器定位时抛出 Since: 1.2 See Also: forName(String), ClassLoadernewInstancepublic Object newInstance()

throws InstantiationException,

IllegalAccessException

Creates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list. The class is initialized if it has not already been initialized. 创建一个新的该Class对象表示的类的实例。该类使用不带参数的new表达式实例化。如果该类还没有初始化时进行初始化。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.PUBLIC作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Returns: a newly allocated instance of the class represented by this object. 一个新创建的该对象表示的类的实例。 Throws: IllegalAccessException - if the class or its nullary constructor is not accessible. 如果该类或者它的默认构造函数不能访问时抛出。 InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason. 如果该Class表示一个抽象类、接口、数组类、简单类型或者void,或者该类没有默认构造函数, 或者因为其他原因实例化失败时抛出。 ExceptionInInitializerError - if the initialization provoked by this method fails. 如果该方法激发的初始化失败时抛出。 SecurityException - if there is no permission to create a new instance. 如果没有创建新实例的许可时抛出。isInstancepublic boolean isInstance(Object obj)

Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise. 确定指定的Object是否可赋值给该Class表示的对象。该方法相当于Java语言 instanceof操作符。如果指定的Object参数不为null,可以转换成该Class表示的引用类型而不抛出ClassCastException,返回true,否则,返回false。 Specifically, if this Class object represents a declared class, this method returns true if the specified Object argument is an instance of the represented class (or of any of its subclasses); it returns false otherwise. If this Class object represents an array class, this method returns true if the specified Object argument can be converted to an object of the array class by an identity conversion or by a widening reference conversion; it returns false otherwise. If this Class object represents an interface, this method returns true if the class or any superclass of the specified Object argument implements this interface; it returns false otherwise. If this Class object represents a primitive type, this method returns false. 特别地,如果该Class对象表示声明的类,当指定的Object参数是代表类的实例( 或者它的子类),方法返回true,否则返回false。如果该Class对象表示数组类, 当指定的Object参数通过类型转换或者通用转换,方法返回true,否则返回 false。如果该Class对象表示接口,当指定的Object参数的类或任一父类实现了该接口 返回true,否则返回false。

Parameters: obj - the object to check 要检查的对象 Returns: true if obj is an instance of this class 如果obj是该类的实例返回true Since: JDK1.1 isAssignableFrompublic boolean isAssignableFrom(Class cls)

Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false. If this Class object represents a primitive type, this method returns true if the specified Class parameter is exactly this Class object; otherwise it returns false. 确定该Class对象表示的类或接口是否和指定的Class变量表示的类或接口相同,或者是其的父类、父接口。如果是,返回true,否则返回false。如果该Class对象表示简单类型,当指定的Class参数实际上是该Class对象时,方法返回true,否则返回false。 Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details. 特别地,该方法用于检查指定的Class参数是否能通过类型转换或者通用转换成Class对象表示的类型。 详细信息查看Java语言规范5.1.1和5.1.4节。

Parameters: cls - the Class object to be checked 要被检查的Class对象 Returns: the boolean value indicating whether objects of the type cls can be assigned to objects of this class 表示cls类型的对象能否赋值给该类的对象的boolean值 Throws: NullPointerException - if the specified Class parameter is null. 如果指定Class变量是null时抛出。 Since: JDK1.1 isInterfacepublic boolean isInterface()

Determines if the specified Class object represents an interface type. 确定指定的Class对象是否表示接口类型。

Returns: true if this object represents an interface; false otherwise. 如果该对象表示接口,返回true,否则为false。isArraypublic boolean isArray()

Determines if this Class object represents an array class. 确定该Class对象是否表示数组类。

Returns: true if this object represents an array class; false otherwise. 如果该对象表示数组类,返回true,否则为false。 Since: JDK1.1 isPrimitivepublic boolean isPrimitive()

Determines if the specified Class object represents a primitive type. 确定指定的Class对象是否表示简单类型。 There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double. 有九种预定义的Class对象来表示八种简单类型+void。它们在Java虚拟机中被创建时,同它们表示的简单类型有相同的名称,称为boolean、byte、char、short、int、long、float 和double。

These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true. 这些对象只能够通过类静态变量访问,只有这些Class对象的方法来返回true。

Returns: true if and only if this class represents a primitive type 只有当该类表示简单类型时返回true Since: JDK1.1 See Also: Boolean.TYPE, Character.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, Void.TYPEgetNamepublic String getName()

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String. 以String形式返回该Class表示的实体(类、接口、简单类型或void)的名称。 If this class object represents a reference type that is not an array type then the binary name of the class is returned, as specified by the Java Language Specification, Second Edition. 如果该类对象表示引用类型,而不是数组类型,那么返回该类的二进制名称,说明见Java语言规范(第二版)。

If this class object represents a primitive type or void, then the name returned is a String equal to the Java language keyword corresponding to the primitive type or void. 如果该类对象表示简单类型或者void,那么返回的名称是个String,等于相应简单类型或void的Java语言关键字。

If this class object represents a class of arrays, then the internal form of the name consists of the name of the element type preceded by one or more '[' characters representing the depth of the array nesting. The encoding of element type names is as follows: 如果该类对象表示数组类,那么名称的内部格式由成员类型的名称组成,以一个或多个 ‘[’字符开头,表示数组嵌套的深度。成员类型名称的编码如下所示:

Element Type Encoding boolean

Z

byte

B

char

C

class or interface

Lclassname;

double

D

float

F

int

I

long

J

short

S

The class or interface name classname is the binary name of the class specified above. 类或接口的名称classname是以上指定类的二进制名称。

Examples:

String.class.getName()

returns "java.lang.String"

byte.class.getName()

returns "byte"

(new Object[3]).getClass().getName()

returns "[Ljava.lang.Object;"

(new int[3][4][5][6][7][8][9]).getClass().getName()

returns "[[[[[[[I"

Returns: the name of the class or interface represented by this object. 该对象表示类或接口的名称。getClassLoaderpublic ClassLoader getClassLoader()

Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader. 返回该类的类加载器。某些实现可能使用null表示引导类加载器。在那样的实现中如果该类被引导类加载器加载方法返回null。 If a security manager is present, and the caller's class loader is not null and the caller's class loader is not the same as or an ancestor of the class loader for the class whose class loader is requested, then this method calls the security manager's checkPermission method with a RuntimePermission("getClassLoader") permission to ensure it's ok to access the class loader for the class. 如果存在安全管理器,调用者的类加载器不为null且调用者的类加载器不同于被调用者类 加载器,也不是被调用者的类加载器的祖先,那么方法使用RuntimePermission("getClassLoader") 许可调用安全管理器的checkPermission以确认可以访问该类的类加载器。

If this object represents a primitive type or void, null is returned. 如果该对象表示简单类型或void,那么返回null。

Returns: the class loader that loaded the class or interface represented by this object. 加载该对象表示的类或接口的类加载器。 Throws: SecurityException - if a security manager exists and its checkPermission method denies access to the class loader for the class. 如果安全管理器存在,它的checkPermission方法拒绝访问该类的类加载器。 See Also: ClassLoader, SecurityManager.checkPermission(java.security.Permission), RuntimePermissiongetSuperclasspublic Class getSuperclass()

Returns the Class representing the superclass of the entity (class, interface, primitive type or void) represented by this Class. If this Class represents either the Object class, an interface, a primitive type, or void, then null is returned. If this object represents an array class then the Class object representing the Object class is returned. 返回该Class表示的实体(类、接口、简单类型或void)的父类的Class对象。 如果该Class表示Object类、接口、简单类型或者void,那么返回null。 如果该对象表示数组类,那么返回表示Object类的Class对象。

Returns: the superclass of the class represented by this object. 该对象表示的类的父类。getPackagepublic Package getPackage()

Gets the package for this class. The class loader of this class is used to find the package. If the class was loaded by the bootstrap class loader the set of packages loaded from CLASSPATH is searched to find the package of the class. Null is returned if no package object was created by the class loader of this class. 获得该类的包。该类的类加载器用于查找包。如果该类被引导类加载器装载,从CLASSPATH 中查找该类的包。如果该类的类加载器没有创建包对象,返回null。 Packages have attributes for versions and specifications only if the information was defined in the manifests that accompany the classes, and if the class loader created the package instance with the attributes from the manifest. 只有当伴随class文件的声明中定义有版本和详细说明的信息,且类加载器使用了声明中属性创建包实例, 返回的包才有该属性。

Returns: the package of the class, or null if no package information is available from the archive or codebase. 类的包,如果包信息不可用时返回null。getInterfacespublic Class[] getInterfaces()

Determines the interfaces implemented by the class or interface represented by this object. 返回该对象表示的类或接口所实现的接口。 If this object represents a class, the return value is an array containing objects representing all interfaces implemented by the class. The order of the interface objects in the array corresponds to the order of the interface names in the implements clause of the declaration of the class represented by this object. For example, given the declaration: 如果该对象表示类,返回值为表示该类实现的所有接口的对象数组。 数组中接口对象的顺序按照该对象表示的类中implements子句声明的接口名称顺序。 例如,给出以下声明:

class Shimmer implements FloorWax, DessertTopping { ... }

suppose the value of s is an instance of Shimmer; the value of the expression: 假设值s是Shimmer的实例,表达式 s.getClass().getInterfaces()[0]

is the Class object that represents interface FloorWax; and the value of: 值为表示接口FloorWax的Class对象。 s.getClass().getInterfaces()[1]

is the Class object that represents interface DessertTopping. 值为表示接口DessertTopping的Class对象。 If this object represents an interface, the array contains objects representing all interfaces extended by the interface. The order of the interface objects in the array corresponds to the order of the interface names in the extends clause of the declaration of the interface represented by this object. 如果该对象表示接口,数组包含的对象表示该接口继承的所有接口。数组中接口对象的顺序按照该对象表示的类中extends子句声明的接口名称顺序。

If this object represents a class or interface that implements no interfaces, the method returns an array of length 0. 如果该对象表示的类或接口未实现接口,方法返回的数组长度为0。

If this object represents a primitive type or void, the method returns an array of length 0. 如果该对象表示简单类型或void,方法返回的数组长度为0。

Returns: an array of interfaces implemented by this class. 该类实现的接口数组。getComponentTypepublic Class getComponentType()

Returns the Class representing the component type of an array. If this class does not represent an array class this method returns null. 返回一Class对象,表示数组的成员类型。如果该类不表示数组类,方法返回null。

Returns: the Class representing the component type of this class if this class is an array 如果该类是数组,返回表示该类的成员类型的Class Since: JDK1.1 See Also: ArraygetModifierspublic int getModifiers()

Returns the Java language modifiers for this class or interface, encoded in an integer. The modifiers consist of the Java Virtual Machine's constants for public, protected, private, final, static, abstract and interface; they should be decoded using the methods of class Modifier. 返回该类或接口的Java语言修饰符,编码成整数型。修饰符由Java虚拟机的常量public、protected、 private、final、static、abstract和interface组成,他们将使用Modifier类的方法进行编码。 If the underlying class is an array class, then its public, private and protected modifiers are the same as those of its component type. If this Class represents a primitive type or void, its public modifier is always true, and its protected and private modifiers are always false. If this object represents an array class, a primitive type or void, then its final modifier is always true and its interface modifier is always false. The values of its other modifiers are not determined by this specification. 如果该类是个数组类,那么它的public、private和protected修饰符和它的成员类型相同。如果该Class表示简单类型或void,它的public修饰符总是为true,protected和private修饰符总是为false。如果该对象表示数组类、简单类型或void,那么它的final修饰符总是为true,它的interface修饰符总是为false。其他修饰符的值在规范中未定义。

The modifier encodings are defined in The Java Virtual Machine Specification, table 4.1. 修饰符编码在Java虚拟机规范表4.2中定义。

Returns: the int representing the modifiers for this class 表示该类修饰符的int Since: JDK1.1 See Also: ModifiergetSignerspublic Object[] getSigners()

Gets the signers of this class. 获得该类的签名者。

Returns: the signers of this class, or null if there are no signers. In particular, this method returns null if this object represents a primitive type or void. 该类的签名者,如果没有签名者,返回null。特别地,如果该对象表示 简单类型或void,方法返回null。 Since: JDK1.1 getDeclaringClasspublic Class getDeclaringClass()

If the class or interface represented by this Class object is a member of another class, returns the Class object representing the class in which it was declared. This method returns null if this class or interface is not a member of any other class. If this Class object represents an array class, a primitive type, or void,then this method returns null. 如果该Class对象表示的类或接口是另一个类的成员,返回表示该类的Class对象。 如果该类或接口不是任意其他类的成员,返回null。如果Class对象表示数组类、简单类型或void,那么方法返回null。

Returns: the declaring class for this class 声明该类的类 Since: JDK1.1 getClassespublic Class[] getClasses()

Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object. This includes public class and interface members inherited from superclasses and public class and interface members declared by the class. This method returns an array of length 0 if this Class object has no public member classes or interfaces. This method also returns an array of length 0 if this Class object represents a primitive type, an array class, or void. 返回一Class对象数组,表示该Class对象表示的类中的所有作为成员的公共类和接口。 包括从父类继承的公共类和接口成员以及该类声明的公共类和接口成员。 如果该Class对象中不含公共成员类或接口,方法返回的数组长度为0。如果该Class对象表示简单类型、数组类或void,方法返回的数组长度也为0。 For this class and each of its superclasses, the following security checks are performed: If there is a security manager, the security manager's checkMemberAccess method is called with this and Member.PUBLIC as its arguments, where this is this class or the superclass whose members are being determined. If the class is in a package, then the security manager's checkPackageAccess method is also called with the package name as its argument. Either of these calls could result in a SecurityException. 对于该类和它的每一级父类,应执行以下安全检查: 如果存在安全管理器,方法首先使用this和Member.PUBLIC作为参数调用安全管理器的checkMemberAccess方法, 这里的this是this类或者成员被确定的父类。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Returns: the array of Class objects representing the public members of this class 表示给类公共成员的Class对象数组 Throws: SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getFieldspublic Field[] getFields()

throws SecurityException

Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface has no accessible public fields, or if it represents an array class, a primitive type, or void. 返回一Field对象数组,映射该Class对象表示的类或接口中的所有可访问公共域。数组中的成员是无序的。如果该类或接口没有可访问的公共域,或者它表示数组类、简单类型或void,方法返回的数组长度为0。 Specifically, if this Class object represents a class, this method returns the public fields of this class and of all its superclasses. If this Class object represents an interface, this method returns the fields of this interface and of all its superinterfaces. 特别地,如果该Class对象表示类,方法返回该类和它所有父类的公共域,如果该Class对象表示接口,方法返回该接口和它所有父接口的域。

If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.PUBLIC作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

The implicit length field for array class is not reflected by this method. User code should use the methods of class Array to manipulate arrays. 该方法不会映射数组类的隐含length域,用户代码应该使用Array类的方法类操作数组。

See The Java Language Specification, sections 8.2 and 8.3. 查看Java语言规范8.2和8.3节。

Returns: the array of Field objects representing the public fields 表示公共域的Field对象数组 Throws: SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Field, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getMethodspublic Method[] getMethods()

throws SecurityException

Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if this Class object represents a class or interface that has no public member methods, or if this Class object represents an array class, primitive type, or void. 返回一Method对象数组,映射该Class对象表示的类或接口中声明的所有公共成员方法,包括类或接口中声明的和从父类或父接口中继承的。数组中的成员是无序的。如果该Class对象表示的类或接口没有公共成员方法,或者它表示数组类、简单类型或void,方法返回的数组长度为0。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.PUBLIC作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

The class initialization method <clinit> is not included in the returned array. If the class declares multiple public member methods with the same parameter types, they are all included in the returned array. 返回数组中不包括该类的初始化方法<clinit>。如果该类使用相同的参数类型声明了多个公共成员方法,返回数组中都会包括。

See The Java Language Specification, sections 8.2 and 8.4. 查看Java语言规范8.2和8.4节。

Returns: the array of Method objects representing the public methods of this class 表示该类公共方法的Method对象数组 Throws: SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Method, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getConstructorspublic Constructor[] getConstructors()

throws SecurityException

Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. An array of length 0 is returned if the class has no public constructors, or if the class is an array class, or if the class reflects a primitive type or void. 返回一Constructor对象数组,映射该Class对象表示的类中所有公共构造函数。如果该类没有公共构造函数,或者是数组类,或者映射简单类型或void,则返回的数组长度为0。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.PUBLIC作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Returns: the array containing Method objects for all the declared public constructors of this class matches the specified parameterTypes 该类中匹配指定parameterTypes的所有声明的公共构造函数的Method对象数组 Throws: SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Constructor, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getFieldpublic Field getField(String name)

throws NoSuchFieldException,

SecurityException

Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object. The name parameter is a String specifying the simple name of the desired field. 返回一Field对象,映射该Class对象表示的类或接口中的指定公共成员域。 name变量是String类型,指定期望域的简单名称。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.PUBLIC作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

The field to be reflected is determined by the algorithm that follows. Let C be the class represented by this object: 映射的域由以下算法确定。假定C是表示该对象的类。

If C declares a public field with the name specified, that is the field to be reflected. 如果C声明了指定名称的公共域,那么该域被映射。 If no field was found in step 1 above, this algorithm is applied recursively to each direct superinterface of C. The direct superinterfaces are searched in the order they were declared. 如果步骤1未找到域,该算法被递归应用至C的每一个上一级父接口。 上一级父接口按它们声明的顺序查找。 If no field was found in steps 1 and 2 above, and C has a superclass S, then this algorithm is invoked recursively upon S. If C has no superclass, then a NoSuchFieldException is thrown. 如果步骤1、2未找到域,C有父类S,那么该算法被S递归调用。如果C没有父类,那么抛出NoSuchFieldException。 See The Java Language Specification, sections 8.2 and 8.3. 查看Java语言规范8.2和8.3节。

Parameters: name - the field name 域名 Returns: the Field object of this class specified by name 该类中指定name的Field对象 Throws: NoSuchFieldException - if a field with the specified name is not found. 如果指定名称的域未找到时抛出。 NullPointerException - if name is null 如果name是null时抛出 SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Field, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getMethodpublic Method getMethod(String name,

Class[] parameterTypes)

throws NoSuchMethodException,

SecurityException

Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object. The name parameter is a String specifying the simple name the desired method. The parameterTypes parameter is an array of Class objects that identify the method's formal parameter types, in declared order. If parameterTypes is null, it is treated as if it were an empty array. 返回一Method对象,映射该Class对象表示的类或接口中的指定公共成员方法。 name变量是String类型,指定期望方法的简单名称。parameterTypes变量是个Class 对象的数组,按声明的顺序识别方法的参数类型。如果parameterTypes为null,把它看成空数组。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.PUBLIC作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

If the name is "<init>"or "<clinit>" a NoSuchMethodException is raised. Otherwise, the method to be reflected is determined by the algorithm that follows. Let C be the class represented by this object: 如果名称是“<init>”或“<clinit>”,生成NoSuchMethodException。 否则,被映射的方法根据以下算法来决定。假设C是表示该对象的类:

C is searched for any matching methods. If no matching method is found, the algorithm of step 1 is invoked recursively on the superclass of C. 在C中查找相匹配的方法。如果未找到匹配方法,在C的父类中递归调用该算法步骤1。 If no method was found in step 1 above, the superinterfaces of C are searched for a matching method. If any such method is found, it is reflected. 如果以上步骤1中未找到方法,继续在C的父接口中查找。如果能找到那样的方法,则被映射。 To find a matching method in a class C: If C declares exactly one public method with the specified name and exactly the same formal parameter types, that is the method reflected. If more than one such method is found in C, and one of these methods has a return type that is more specific than any of the others, that method is reflected; otherwise one of the methods is chosen arbitrarily. 在C类中查找匹配方法:如果C中恰好声明了一个指定名称和相同参数类型的公共方法, 那么映射该方法。如果C中有多个那样的方法,其中有一个方法比其他方法的返回类型更具体,那么返回该方法,否则随机选择其中之一。 See The Java Language Specification, sections 8.2 and 8.4. 查看Java语言规范8.2和8.4节。

Parameters: name - the name of the method 方法名称 parameterTypes - the list of parameters 变量列表 Returns: the Method object that matches the specified name and parameterTypes 匹配指定name和parameterTypes的Method对象 Throws: NoSuchMethodException - if a matching method is not found or if the name is "<init>"or "<clinit>". 如果匹配方法未找到或者名称为“<init>”或“<clinit>”则抛出。 NullPointerException - if name is null 如果name是null时抛出 SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Method, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getConstructorpublic Constructor getConstructor(Class[] parameterTypes)

throws NoSuchMethodException,

SecurityException

Returns a Constructor object that reflects the specified public constructor of the class represented by this Class object. The parameterTypes parameter is an array of Class objects that identify the constructor's formal parameter types, in declared order. 返回一Constructor对象,映射该Class对象表示的类的指定公共构造函数。parameterTypes 变量是Class对象的数组,以声明顺序表示构造函数的变量类型 The constructor to reflect is the public constructor of the class represented by this Class object whose formal parameter types match those specified by parameterTypes. 如果该Class对象表示的类中的公共构造函数的参数类型匹配指定的parameterTypes,那么映射该构造函数。

If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.PUBLIC作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Parameters: parameterTypes - the parameter array 变量数组 Returns: the Method object of the public constructor that matches the specified parameterTypes 匹配指定name和parameterTypes的公共构造函数的Method对象 Throws: NoSuchMethodException - if a matching method is not found. 如果匹配方法未找到则抛出。 SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Constructor, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getDeclaredClassespublic Class[] getDeclaredClasses()

throws SecurityException

Returns an array of Class objects reflecting all the classes and interfaces declared as members of the class represented by this Class object. This includes public, protected, default (package) access, and private classes and interfaces declared by the class, but excludes inherited classes and interfaces. This method returns an array of length 0 if the class declares no classes or interfaces as members, or if this Class object represents a primitive type, an array class, or void. 返回一Class对象的数组,映射该Class对象表示的类中作为成员声明的所有类和接口。包括该类中声明的public、protected、default(package访问)和private类和接口,但是不包括继承的类和接口。如果该类不含声明为成员的类或接口,或者该Class对象表示简单类型、数组类或void,方法返回的数组长度为0。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.DECLARED as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.DECLARED作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Returns: the array of Class objects representing all the declared members of this class 表示该类所有声明成员的Class对象数组 Throws: SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getDeclaredFieldspublic Field[] getDeclaredFields()

throws SecurityException

Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface declares no fields, or if this Class object represents a primitive type, an array class, or void. 返回一Field对象数组,映射该Class对象表示的类或接口中声明的所有域。包括public、protected、default(package访问)和private域,但是不包括继承的域。数组中的成员是无序的。如果该类或接口中未声明域,或者该Class对象表示简单类型、数组类或void,方法返回的数组长度为0。 See The Java Language Specification, sections 8.2 and 8.3. 查看Java语言规范8.2和8.3节。

If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.DECLARED as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.DECLARED作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Returns: the array of Field objects representing all the declared fields of this class 表示该类所有声明域的Field对象数组 Throws: SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Field, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getDeclaredMethodspublic Method[] getDeclaredMethods()

throws SecurityException

Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private methods, but excludes inherited methods. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface declares no methods, or if this Class object represents a primitive type, an array class, or void. The class initialization method <clinit> is not included in the returned array. If the class declares multiple public member methods with the same parameter types, they are all included in the returned array. 返回一Method对象数组,映射该Class对象表示的类或接口中声明的所有方法。包括public、protected、default(package访问)和private方法,但是不包括继承的方法。数组中的成员是无序的。如果该类或接口中未声明方法,或者该Class对象表示简单类型、数组类或void,方法返回的数组长度为0。返回数组中不包括该类的初始化方法<clinit>。如果该类使用相同的参数类型声明了多个公共成员方法,返回数组中都会包括。 See The Java Language Specification, section 8.2. 查看Java语言规范8.2节。

If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.DECLARED as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.DECLARED作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Returns: the array of Method objects representing all the declared methods of this class 表示该类中所有声明方法的Method对象数组 Throws: SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Method, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getDeclaredConstructorspublic Constructor[] getDeclaredConstructors()

throws SecurityException

Returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object. These are public, protected, default (package) access, and private constructors. The elements in the array returned are not sorted and are not in any particular order. If the class has a default constructor, it is included in the returned array. This method returns an array of length 0 if this Class object represents an interface, a primitive type, an array class, or void. 返回一Constructor对象数组,映射该Class对象表示的类中的所有声明的构造函数。包括public、protected、default(package访问)和private构造函数。数组中的成员是无序的。如果该类有个默认构造函数,返回数组中包括。如果该Class对象表示简单类型、数组类或void,方法返回的数组长度为0。 See The Java Language Specification, section 8.2. 查看Java语言规范8.2节。

If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.DECLARED as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.DECLARED作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Returns: the array of Method objects representing all the declared constructors of this class 表示该类中所有声明构造函数的Method对象数组 Throws: SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Constructor, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getDeclaredFieldpublic Field getDeclaredField(String name)

throws NoSuchFieldException,

SecurityException

Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object. The name parameter is a String that specifies the simple name of the desired field. Note that this method will not reflect the length field of an array class. 返回一Field对象,映射该Class对象表示的类或接口中的指定声明域。 name变量是String类型,指定期望域的简单名称。注意该方法不会映射数组类的length域。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.DECLARED as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.DECLARED作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Parameters: name - the name of the field 域的名称 Returns: the Field object for the specified field in this class 该类中指定域的Field对象 Throws: NoSuchFieldException - if a field with the specified name is not found. 如果指定名称的域未找到时抛出。 NullPointerException - if name is null 如果name是null时抛出 SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Field, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getDeclaredMethodpublic Method getDeclaredMethod(String name,

Class[] parameterTypes)

throws NoSuchMethodException,

SecurityException

Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object. The name parameter is a String that specifies the simple name of the desired method, and the parameterTypes parameter is an array of Class objects that identify the method's formal parameter types, in declared order. If more than one method with the same parameter types is declared in a class, and one of these methods has a return type that is more specific than any of the others, that method is returned; otherwise one of the methods is chosen arbitrarily. If the name is "<init>"or "<clinit>" a NoSuchMethodException is raised. 返回一Method对象,映射该Class对象表示的类或接口中的指定声明方法。 name变量是String类型,指定期望方法的简单名称, parameterTypes 变量是Class对象的数组,以声明顺序表示方法的变量类型。如果类中相同变量类型的方法声明了多个,其中有一个方法比其他方法的返回类型更具体,那么返回该方法,否则随机选择其中之一。如果名称是“<init>”或“<clinit>”,生成NoSuchMethodException。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.DECLARED as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.DECLARED作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Parameters: name - the name of the method 方法名称 parameterTypes - the parameter array 变量数组 Returns: the Method object for the method of this class matching the specified name and parameters 该类中匹配指定名称和变量的Method对象 Throws: NoSuchMethodException - if a matching method is not found. 如果匹配方法未找到则抛出。 NullPointerException - if name is null 如果name是null时抛出 SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Method, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getDeclaredConstructorpublic Constructor getDeclaredConstructor(Class[] parameterTypes)

throws NoSuchMethodException,

SecurityException

Returns a Constructor object that reflects the specified constructor of the class or interface represented by this Class object. The parameterTypes parameter is an array of Class objects that identify the constructor's formal parameter types, in declared order. 返回一Constructor对象,映射该Class对象表示的类或接口中的指定构造函数。 parameterTypes变量是Class对象的数组,以声明顺序表示构造函数的变量类型。 If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.DECLARED as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. 如果存在安全管理器,方法首先使用this和Member.DECLARED作为参数调用安全管理器的checkMemberAccess方法。 如果该类在包中,那么方法还使用包名作为参数调用安全管理器的checkPackageAccess方法。 每一次调用都可能导致SecurityException。

Parameters: parameterTypes - the parameter array 变量数组 Returns: The Method object for the constructor with the specified parameter list 匹配指定变量列表的构造函数的Method对象 Throws: NoSuchMethodException - if a matching method is not found. 如果匹配方法未找到则抛出。 SecurityException - if access to the information is denied. 如果访问信息被拒绝时抛出。 Since: JDK1.1 See Also: Constructor, SecurityManager.checkMemberAccess(Class, int), SecurityManager.checkPackageAccess(String)getResourceAsStreampublic InputStream getResourceAsStream(String name)

Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the defining class loader of the class. 通过指定名称查找资源。如果未找到该名称的资源,方法返回null。查找与给定类的相关资源规则由定义该类的类加载器实现。 This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResourceAsStream. 方法在对资源名称作以下改变后将该调用委派给类加载器:如果资源名称以“/”开头,将不作改变; 否则在把“.”转换成“/”后,包名作为资源名。如果该对象由引导类加载器加载,调用委派给 ClassLoader.getSystemResourceAsStream。

Parameters: name - name of the desired resource 期望的资源名称 Returns: a java.io.InputStream object. java.io.InputStream对象。 Throws: NullPointerException - if name is null. 如果name是null时抛出。 Since: JDK1.1 See Also: ClassLoadergetResourcepublic URL getResource(String name)

Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the * defining class loader of the class. 通过指定名称查找资源。如果未找到该名称的资源,方法返回null。查找与给定类的相关资源规则由定义该类的类加载器实现。 This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResource. 方法在对资源名称作以下改变后将该调用委派给类加载器:如果资源名称以“/”开头,将不作改变; 否则在把“.”转换成“/”后,包名作为资源名。如果该对象由引导类加载器加载,调用委派给 ClassLoader.getSystemResourceAsStream。

Parameters: name - name of the desired resource 期望的资源名称 Returns: a java.net.URL object. java.net.URL对象 Since: JDK1.1 See Also: ClassLoadergetProtectionDomainpublic ProtectionDomain getProtectionDomain()

Returns the ProtectionDomain of this class. If there is a security manager installed, this method first calls the security manager's checkPermission method with a RuntimePermission("getProtectionDomain") permission to ensure it's ok to get the ProtectionDomain. 返回该类的ProtectionDomain。如果装有安全管理器,方法首先使用RuntimePermission("getProtectionDomain")许可调用安全管理的checkPermission方法,以确认可以获得ProtectionDomain。

Returns: the ProtectionDomain of this class 类的ProtectionDomain Throws: SecurityException - if a security manager exists and its checkPermission method doesn't allow getting the ProtectionDomain. 如果安全管理器存在,它的checkPermission方法不允许获得ProtectionDomain时抛出。 Since: 1.2 See Also: ProtectionDomain, SecurityManager.checkPermission(java.security.Permission), RuntimePermissiondesiredAssertionStatuspublic boolean desiredAssertionStatus()

Returns the assertion status that would be assigned to this class if it were to be initialized at the time this method is invoked. If this class has had its assertion status set, the most recent setting will be returned; otherwise, if any package default assertion status pertains to this class, the most recent setting for the most specific pertinent package default assertion status is returned; otherwise, if this class is not a system class (i.e., it has a class loader) its class loader's default assertion status is returned; otherwise, the system class default assertion status is returned. 如果调用该方法时该类将被初始化,返回指定给该类的断言状态。 如果当前类已指定了断言状态,方法返回其断言状态的最新值,如果存在与当前类相关联的包的默认断言状态, 返回此默认断言状态的最新值,如果当前类不是系统类(即类加载器), 返回当前类加载器的默认断言状态,否则返回系统类的默认断言状态。 Few programmers will have any need for this method; it is provided for the benefit of the JRE itself. (It allows a class to determine at the time that it is initialized whether assertions should be enabled.) Note that this method is not guaranteed to return the actual assertion status that was (or will be) associated with the specified class when it was (or will be) initialized. 很少有程序员需要该方法,它只提供给JRE本身(允许类初始化时确定是否能够断言)。 注意当指定类初始化时,该方法不保证返回与其关联的实际断言状态。

Returns: the desired assertion status of the specified class. 指定类的期望断言状态。 Since: 1.4 See Also: ClassLoader.setClassAssertionStatus(java.lang.String, boolean), ClassLoader.setPackageAssertionStatus(java.lang.String, boolean), ClassLoader.setDefaultAssertionStatus(boolean)[/url][url=file:///F:/资料/文字资料/j2sdk-1_4_2-doc/docs/api/overview-summary.html]Overview

Package

Class

Use

Tree

Deprecated

Index

Help

JavaTM 2 Platform

Std. Ed. v1.4.2

PREV CLASS NEXT CLASS

FRAMES NO FRAMES All Classes

SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature

For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有