1 *java.lang.Class* *Class* Instances of the class Class represent classes and
4 public final class Class
5 extends |java.lang.Object|
6 implements |java.io.Serializable|
7 |java.lang.reflect.GenericDeclaration|
8 |java.lang.reflect.Type|
9 |java.lang.reflect.AnnotatedElement|
11 |java.lang.Class_Description|
12 |java.lang.Class_Fields|
13 |java.lang.Class_Constructors|
14 |java.lang.Class_Methods|
16 ================================================================================
18 *java.lang.Class_Methods*
19 |java.lang.Class.asSubclass(Class)|Casts this Class object to represent a subcl
20 |java.lang.Class.cast(Object)|Casts an object to the class or interface represe
21 |java.lang.Class.desiredAssertionStatus()|Returns the assertion status that wou
22 |java.lang.Class.forName(String)|Returns the Class object associated with the c
23 |java.lang.Class.forName(String,boolean,ClassLoader)|Returns the Class object a
24 |java.lang.Class.getAnnotation(Class)|
25 |java.lang.Class.getAnnotations()|
26 |java.lang.Class.getCanonicalName()|Returns the canonical name of the the under
27 |java.lang.Class.getClasses()|Returns an array containing Class objects represe
28 |java.lang.Class.getClassLoader()|Returns the class loader for the class.
29 |java.lang.Class.getComponentType()|Returns the Class representing the componen
30 |java.lang.Class.getConstructor(Class[])|Returns a Constructor object that refl
31 |java.lang.Class.getConstructors()|Returns an array containing Constructor obje
32 |java.lang.Class.getDeclaredAnnotations()|
33 |java.lang.Class.getDeclaredClasses()|Returns an array of Class objects reflect
34 |java.lang.Class.getDeclaredConstructor(Class[])|Returns a Constructor object t
35 |java.lang.Class.getDeclaredConstructors()|Returns an array of Constructor obje
36 |java.lang.Class.getDeclaredField(String)|Returns a Field object that reflects
37 |java.lang.Class.getDeclaredFields()|Returns an array of Field objects reflecti
38 |java.lang.Class.getDeclaredMethod(String,Class[])|Returns a Method object that
39 |java.lang.Class.getDeclaredMethods()|Returns an array of Method objects reflec
40 |java.lang.Class.getDeclaringClass()|If the class or interface represented by t
41 |java.lang.Class.getEnclosingClass()|Returns the immediately enclosing class of
42 |java.lang.Class.getEnclosingConstructor()|If this Class object represents a lo
43 |java.lang.Class.getEnclosingMethod()|If this Class object represents a local o
44 |java.lang.Class.getEnumConstants()|Returns the elements of this enum class or
45 |java.lang.Class.getField(String)|Returns a Field object that reflects the spec
46 |java.lang.Class.getFields()|Returns an array containing Field objects reflecti
47 |java.lang.Class.getGenericInterfaces()|Returns the Types representing the inte
48 |java.lang.Class.getGenericSuperclass()|Returns the Type representing the direc
49 |java.lang.Class.getInterfaces()|Determines the interfaces implemented by the c
50 |java.lang.Class.getMethod(String,Class[])|Returns a Method object that reflect
51 |java.lang.Class.getMethods()|Returns an array containing Method objects reflec
52 |java.lang.Class.getModifiers()|Returns the Java language modifiers for this cl
53 |java.lang.Class.getName()|Returns the name of the entity (class, interface, a
54 |java.lang.Class.getPackage()|Gets the package for this class.
55 |java.lang.Class.getProtectionDomain()|Returns the ProtectionDomain of this cla
56 |java.lang.Class.getResource(String)|Finds a resource with a given name.
57 |java.lang.Class.getResourceAsStream(String)|Finds a resource with a given name
58 |java.lang.Class.getSigners()|Gets the signers of this class.
59 |java.lang.Class.getSimpleName()|Returns the simple name of the underlying clas
60 |java.lang.Class.getSuperclass()|Returns the Class representing the superclass
61 |java.lang.Class.getTypeParameters()|Returns an array of TypeVariable objects t
62 |java.lang.Class.isAnnotation()|Returns true if this Class object represents an
63 |java.lang.Class.isAnnotationPresent(Class)|
64 |java.lang.Class.isAnonymousClass()|Returns true if and only if the underlying
65 |java.lang.Class.isArray()|Determines if this Class object represents an array
66 |java.lang.Class.isAssignableFrom(Class)|Determines if the class or interface r
67 |java.lang.Class.isEnum()|Returns true if and only if this class was declared a
68 |java.lang.Class.isInstance(Object)|Determines if the specified Object is assig
69 |java.lang.Class.isInterface()|Determines if the specified Class object represe
70 |java.lang.Class.isLocalClass()|Returns true if and only if the underlying clas
71 |java.lang.Class.isMemberClass()|Returns true if and only if the underlying cla
72 |java.lang.Class.isPrimitive()|Determines if the specified Class object represe
73 |java.lang.Class.isSynthetic()|Returns true if this class is a synthetic class;
74 |java.lang.Class.newInstance()|Creates a new instance of the class represented
75 |java.lang.Class.toString()|Converts the object to a string.
77 *java.lang.Class_Description*
79 Instances of the class Class represent classes and interfaces in a running Java
80 application. An enum is a kind of class and an annotation is a kind of
81 interface. Every array also belongs to a class that is reflected as a Class
82 object that is shared by all arrays with the same element type and number of
83 dimensions. The primitive Java types (boolean, byte, char, short, int, long,
84 float, and double), and the keyword void are also represented as Class objects.
86 Class has no public constructor. Instead Class objects are constructed
87 automatically by the Java Virtual Machine as classes are loaded and by calls to
88 the defineClass method in the class loader.
90 The following example uses a Class object to print the class name of an object:
94 void printClassName(Object obj) { System.out.println("The class of " + obj + "
95 is " + obj.getClass().getName()); }
97 It is also possible to get the Class object for a named type (or for void)
98 using a class literal (JLS Section 15.8.2). For example:
102 System.out.println("The name of class Foo is: "+Foo.class.getName());
105 *java.lang.Class.asSubclass(Class)*
107 public |java.lang.Class| asSubclass(java.lang.Class clazz)
109 Casts this Class object to represent a subclass of the class represented by the
110 specified class object. Checks that that the cast is valid, and throws a
111 ClassCastException if it is not. If this method succeeds, it always returns a
112 reference to this class object.
114 This method is useful when a client needs to "narrow" the type of a Class
115 object to pass it to an API that restricts the Class objects that it is willing
116 to accept. A cast would generate a compile-time warning, as the correctness of
117 the cast could not be checked at runtime (because generic types are implemented
121 Returns: this Class object, cast to represent a subclass of the specified class object.
122 *java.lang.Class.cast(Object)*
124 public |java.lang.Object| cast(java.lang.Object obj)
126 Casts an object to the class or interface represented by this Class object.
128 obj - the object to be cast
130 Returns: the object after casting, or null if obj is null
131 *java.lang.Class.desiredAssertionStatus()*
133 public boolean desiredAssertionStatus()
135 Returns the assertion status that would be assigned to this class if it were to
136 be initialized at the time this method is invoked. If this class has had its
137 assertion status set, the most recent setting will be returned; otherwise, if
138 any package default assertion status pertains to this class, the most recent
139 setting for the most specific pertinent package default assertion status is
140 returned; otherwise, if this class is not a system class (i.e., it has a class
141 loader) its class loader's default assertion status is returned; otherwise, the
142 system class default assertion status is returned.
144 Few programmers will have any need for this method; it is provided for the
145 benefit of the JRE itself. (It allows a class to determine at the time that it
146 is initialized whether assertions should be enabled.) Note that this method is
147 not guaranteed to return the actual assertion status that was (or will be)
148 associated with the specified class when it was (or will be) initialized.
151 Returns: the desired assertion status of the specified class.
152 *java.lang.Class.forName(String)*
154 public static |java.lang.Class| forName(java.lang.String className)
155 throws |java.lang.ClassNotFoundException|
157 Returns the Class object associated with the class or interface with the given
158 string name. Invoking this method is equivalent to:
162 Class.forName(className, true, currentLoader)
164 where currentLoader denotes the defining class loader of the current class.
166 For example, the following code fragment returns the runtime Class descriptor
167 for the class named java.lang.Thread:
171 Classt= Class.forName("java.lang.Thread")
173 A call to forName("X") causes the class named X to be initialized.
175 className - the fully qualified name of the desired class.
177 Returns: the Class object for the class with the specified name.
178 *java.lang.Class.forName(String,boolean,ClassLoader)*
180 public static |java.lang.Class| forName(
181 java.lang.String name,
183 java.lang.ClassLoader loader)
184 throws |java.lang.ClassNotFoundException|
186 Returns the Class object associated with the class or interface with the given
187 string name, using the given class loader. Given the fully qualified name for a
188 class or interface (in the same format returned by getName) this method
189 attempts to locate, load, and link the class or interface. The specified class
190 loader is used to load the class or interface. If the parameter loader is null,
191 the class is loaded through the bootstrap class loader. The class is
192 initialized only if the initialize parameter is true and if it has not been
195 If name denotes a primitive type or void, an attempt will be made to locate a
196 user-defined class in the unnamed package whose name is name. Therefore, this
197 method cannot be used to obtain any of the Class objects representing primitive
200 If name denotes an array class, the component type of the array class is loaded
203 For example, in an instance method the expression:
213 Class.forName("Foo", true, this.getClass().getClassLoader())
215 Note that this method throws errors related to loading, linking or initializing
216 as specified in Sections 12.2, 12.3 and 12.4 of The Java Language
217 Specification. Note that this method does not check whether the requested class
218 is accessible to its caller.
220 If the loader is null, and a security manager is present, and the caller's
221 class loader is not null, then this method calls the security manager's
222 checkPermission method with a RuntimePermission("getClassLoader") permission to
223 ensure it's ok to access the bootstrap class loader.
225 name - fully qualified name of the desired class
226 initialize - whether the class must be initialized
227 loader - class loader from which the class must be loaded
229 Returns: class object representing the desired class
230 *java.lang.Class.getAnnotation(Class)*
232 public |java.lang.annotation.Annotation| getAnnotation(java.lang.Class annotationClass)
237 *java.lang.Class.getAnnotations()*
239 public |java.lang.annotation.Annotation| getAnnotations()
244 *java.lang.Class.getCanonicalName()*
246 public |java.lang.String| getCanonicalName()
248 Returns the canonical name of the the underlying class as defined by the Java
249 Language Specification. Returns null if the underlying class does not have a
250 canonical name (i.e., if it is a local or anonymous class or an array whose
251 component type does not have a canonical name).
254 Returns: the canonical name of the underlying class if it exists, and null otherwise.
255 *java.lang.Class.getClasses()*
257 public |java.lang.Class| getClasses()
259 Returns an array containing Class objects representing all the public classes
260 and interfaces that are members of the class represented by this Class object.
261 This includes public class and interface members inherited from superclasses
262 and public class and interface members declared by the class. This method
263 returns an array of length 0 if this Class object has no public member classes
264 or interfaces. This method also returns an array of length 0 if this Class
265 object represents a primitive type, an array class, or void.
268 Returns: the array of Class objects representing the public members of this class
269 *java.lang.Class.getClassLoader()*
271 public |java.lang.ClassLoader| getClassLoader()
273 Returns the class loader for the class. Some implementations may use null to
274 represent the bootstrap class loader. This method will return null in such
275 implementations if this class was loaded by the bootstrap class loader.
277 If a security manager is present, and the caller's class loader is not null and
278 the caller's class loader is not the same as or an ancestor of the class loader
279 for the class whose class loader is requested, then this method calls the
280 security manager's checkPermission method with a
281 RuntimePermission("getClassLoader") permission to ensure it's ok to access the
282 class loader for the class.
284 If this object represents a primitive type or void, null is returned.
287 Returns: the class loader that loaded the class or interface represented by this object.
288 *java.lang.Class.getComponentType()*
290 public native |java.lang.Class| getComponentType()
292 Returns the Class representing the component type of an array. If this class
293 does not represent an array class this method returns null.
296 Returns: the Class representing the component type of this class if this class is an
298 *java.lang.Class.getConstructor(Class[])*
300 public |java.lang.reflect.Constructor| getConstructor(java.lang.Class[] parameterTypes)
301 throws |java.lang.NoSuchMethodException|
302 |java.lang.SecurityException|
304 Returns a Constructor object that reflects the specified public constructor of
305 the class represented by this Class object. The parameterTypes parameter is an
306 array of Class objects that identify the constructor's formal parameter types,
309 The constructor to reflect is the public constructor of the class represented
310 by this Class object whose formal parameter types match those specified by
313 parameterTypes - the parameter array
315 Returns: the Method object of the public constructor that matches the specified
317 *java.lang.Class.getConstructors()*
319 public |java.lang.reflect.Constructor| getConstructors()
320 throws |java.lang.SecurityException|
322 Returns an array containing Constructor objects reflecting all the public
323 constructors of the class represented by this Class object. An array of length
324 0 is returned if the class has no public constructors, or if the class is an
325 array class, or if the class reflects a primitive type or void.
328 Returns: the array containing Method objects for all the declared public constructors of
329 this class matches the specified parameterTypes
330 *java.lang.Class.getDeclaredAnnotations()*
332 public |java.lang.annotation.Annotation| getDeclaredAnnotations()
337 *java.lang.Class.getDeclaredClasses()*
339 public |java.lang.Class| getDeclaredClasses()
340 throws |java.lang.SecurityException|
342 Returns an array of Class objects reflecting all the classes and interfaces
343 declared as members of the class represented by this Class object. This
344 includes public, protected, default (package) access, and private classes and
345 interfaces declared by the class, but excludes inherited classes and
346 interfaces. This method returns an array of length 0 if the class declares no
347 classes or interfaces as members, or if this Class object represents a
348 primitive type, an array class, or void.
351 Returns: the array of Class objects representing all the declared members of this class
352 *java.lang.Class.getDeclaredConstructor(Class[])*
354 public |java.lang.reflect.Constructor| getDeclaredConstructor(java.lang.Class[] parameterTypes)
355 throws |java.lang.NoSuchMethodException|
356 |java.lang.SecurityException|
358 Returns a Constructor object that reflects the specified constructor of the
359 class or interface represented by this Class object. The parameterTypes
360 parameter is an array of Class objects that identify the constructor's formal
361 parameter types, in declared order.
363 parameterTypes - the parameter array
365 Returns: The Method object for the constructor with the specified parameter list
366 *java.lang.Class.getDeclaredConstructors()*
368 public |java.lang.reflect.Constructor| getDeclaredConstructors()
369 throws |java.lang.SecurityException|
371 Returns an array of Constructor objects reflecting all the constructors
372 declared by the class represented by this Class object. These are public,
373 protected, default (package) access, and private constructors. The elements in
374 the array returned are not sorted and are not in any particular order. If the
375 class has a default constructor, it is included in the returned array. This
376 method returns an array of length 0 if this Class object represents an
377 interface, a primitive type, an array class, or void.
379 See The Java Language Specification, section 8.2.
382 Returns: the array of Method objects representing all the declared constructors of this
384 *java.lang.Class.getDeclaredField(String)*
386 public |java.lang.reflect.Field| getDeclaredField(java.lang.String name)
387 throws |java.lang.NoSuchFieldException|
388 |java.lang.SecurityException|
390 Returns a Field object that reflects the specified declared field of the class
391 or interface represented by this Class object. The name parameter is a String
392 that specifies the simple name of the desired field. Note that this method will
393 not reflect the length field of an array class.
395 name - the name of the field
397 Returns: the Field object for the specified field in this class
398 *java.lang.Class.getDeclaredFields()*
400 public |java.lang.reflect.Field| getDeclaredFields()
401 throws |java.lang.SecurityException|
403 Returns an array of Field objects reflecting all the fields declared by the
404 class or interface represented by this Class object. This includes public,
405 protected, default (package) access, and private fields, but excludes inherited
406 fields. The elements in the array returned are not sorted and are not in any
407 particular order. This method returns an array of length 0 if the class or
408 interface declares no fields, or if this Class object represents a primitive
409 type, an array class, or void.
411 See The Java Language Specification, sections 8.2 and 8.3.
414 Returns: the array of Field objects representing all the declared fields of this class
415 *java.lang.Class.getDeclaredMethod(String,Class[])*
417 public |java.lang.reflect.Method| getDeclaredMethod(
418 java.lang.String name,
419 java.lang.Class[] parameterTypes)
420 throws |java.lang.NoSuchMethodException|
421 |java.lang.SecurityException|
423 Returns a Method object that reflects the specified declared method of the
424 class or interface represented by this Class object. The name parameter is a
425 String that specifies the simple name of the desired method, and the
426 parameterTypes parameter is an array of Class objects that identify the
427 method's formal parameter types, in declared order. If more than one method
428 with the same parameter types is declared in a class, and one of these methods
429 has a return type that is more specific than any of the others, that method is
430 returned; otherwise one of the methods is chosen arbitrarily. If the name is
431 "<init>"or "<clinit>" a NoSuchMethodException is raised.
433 name - the name of the method
434 parameterTypes - the parameter array
436 Returns: the Method object for the method of this class matching the specified name and
438 *java.lang.Class.getDeclaredMethods()*
440 public |java.lang.reflect.Method| getDeclaredMethods()
441 throws |java.lang.SecurityException|
443 Returns an array of Method objects reflecting all the methods declared by the
444 class or interface represented by this Class object. This includes public,
445 protected, default (package) access, and private methods, but excludes
446 inherited methods. The elements in the array returned are not sorted and are
447 not in any particular order. This method returns an array of length 0 if the
448 class or interface declares no methods, or if this Class object represents a
449 primitive type, an array class, or void. The class initialization method
450 <clinit> is not included in the returned array. If the class declares multiple
451 public member methods with the same parameter types, they are all included in
454 See The Java Language Specification, section 8.2.
457 Returns: the array of Method objects representing all the declared methods of this class
458 *java.lang.Class.getDeclaringClass()*
460 public native |java.lang.Class| getDeclaringClass()
462 If the class or interface represented by this Class object is a member of
463 another class, returns the Class object representing the class in which it was
464 declared. This method returns null if this class or interface is not a member
465 of any other class. If this Class object represents an array class, a primitive
466 type, or void,then this method returns null.
469 Returns: the declaring class for this class
470 *java.lang.Class.getEnclosingClass()*
472 public |java.lang.Class| getEnclosingClass()
474 Returns the immediately enclosing class of the underlying class. If the
475 underlying class is a top level class this method returns null.
478 Returns: the immediately enclosing class of the underlying class
479 *java.lang.Class.getEnclosingConstructor()*
481 public |java.lang.reflect.Constructor| getEnclosingConstructor()
483 If this Class object represents a local or anonymous class within a
484 constructor, returns a Constructor(|java.lang.reflect.Constructor|) object
485 representing the immediately enclosing constructor of the underlying class.
486 Returns null otherwise. In particular, this method returns null if the
487 underlying class is a local or anonymous class immediately enclosed by a type
488 declaration, instance initializer or static initializer.
491 Returns: the immediately enclosing constructor of the underlying class, if that class is
492 a local or anonymous class; otherwise null.
493 *java.lang.Class.getEnclosingMethod()*
495 public |java.lang.reflect.Method| getEnclosingMethod()
497 If this Class object represents a local or anonymous class within a method,
498 returns a Method(|java.lang.reflect.Method|) object representing the
499 immediately enclosing method of the underlying class. Returns null otherwise.
501 In particular, this method returns null if the underlying class is a local or
502 anonymous class immediately enclosed by a type declaration, instance
503 initializer or static initializer.
506 Returns: the immediately enclosing method of the underlying class, if that class is a
507 local or anonymous class; otherwise null.
508 *java.lang.Class.getEnumConstants()*
510 public |java.lang.Object| getEnumConstants()
512 Returns the elements of this enum class or null if this Class object does not
513 represent an enum type.
516 Returns: an array containing the values comprising the enum class represented by this
517 Class object in the order they're declared, or null if this Class
518 object does not represent an enum type
519 *java.lang.Class.getField(String)*
521 public |java.lang.reflect.Field| getField(java.lang.String name)
522 throws |java.lang.NoSuchFieldException|
523 |java.lang.SecurityException|
525 Returns a Field object that reflects the specified public member field of the
526 class or interface represented by this Class object. The name parameter is a
527 String specifying the simple name of the desired field.
529 The field to be reflected is determined by the algorithm that follows. Let C be
530 the class represented by this object:
532 If C declares a public field with the name specified, that is the field to be
533 reflected. If no field was found in step 1 above, this algorithm is applied
534 recursively to each direct superinterface of C. The direct superinterfaces are
535 searched in the order they were declared. If no field was found in steps 1 and
536 2 above, and C has a superclass S, then this algorithm is invoked recursively
537 upon S. If C has no superclass, then a NoSuchFieldException is thrown.
539 See The Java Language Specification, sections 8.2 and 8.3.
541 name - the field name
543 Returns: the Field object of this class specified by name
544 *java.lang.Class.getFields()*
546 public |java.lang.reflect.Field| getFields()
547 throws |java.lang.SecurityException|
549 Returns an array containing Field objects reflecting all the accessible public
550 fields of the class or interface represented by this Class object. The elements
551 in the array returned are not sorted and are not in any particular order. This
552 method returns an array of length 0 if the class or interface has no accessible
553 public fields, or if it represents an array class, a primitive type, or void.
555 Specifically, if this Class object represents a class, this method returns the
556 public fields of this class and of all its superclasses. If this Class object
557 represents an interface, this method returns the fields of this interface and
558 of all its superinterfaces.
560 The implicit length field for array class is not reflected by this method. User
561 code should use the methods of class Array to manipulate arrays.
563 See The Java Language Specification, sections 8.2 and 8.3.
566 Returns: the array of Field objects representing the public fields
567 *java.lang.Class.getGenericInterfaces()*
569 public |java.lang.reflect.Type| getGenericInterfaces()
571 Returns the Types representing the interfaces directly implemented by the class
572 or interface represented by this object.
574 If a superinterface is a parameterized type, the Type object returned for it
575 must accurately reflect the actual type parameters used in the source code. The
576 parameterized type representing each superinterface is created if it had not
577 been created before. See the declaration of
578 ParameterizedType(|java.lang.reflect.ParameterizedType|) for the semantics of
579 the creation process for parameterized types.
581 If this object represents a class, the return value is an array containing
582 objects representing all interfaces implemented by the class. The order of the
583 interface objects in the array corresponds to the order of the interface names
584 in the implements clause of the declaration of the class represented by this
585 object. In the case of an array class, the interfaces Cloneable and
586 Serializable are returned in that order.
588 If this object represents an interface, the array contains objects representing
589 all interfaces directly extended by the interface. The order of the interface
590 objects in the array corresponds to the order of the interface names in the
591 extends clause of the declaration of the interface represented by this object.
593 If this object represents a class or interface that implements no interfaces,
594 the method returns an array of length 0.
596 If this object represents a primitive type or void, the method returns an array
600 Returns: an array of interfaces implemented by this class
601 *java.lang.Class.getGenericSuperclass()*
603 public |java.lang.reflect.Type| getGenericSuperclass()
605 Returns the Type representing the direct superclass of the entity (class,
606 interface, primitive type or void) represented by this Class.
608 If the superclass is a parameterized type, the Type object returned must
609 accurately reflect the actual type parameters used in the source code. The
610 parameterized type representing the superclass is created if it had not been
611 created before. See the declaration of
612 ParameterizedType(|java.lang.reflect.ParameterizedType|) for the semantics of
613 the creation process for parameterized types. If this Class represents either
614 the Object class, an interface, a primitive type, or void, then null is
615 returned. If this object represents an array class then the Class object
616 representing the Object class is returned.
619 Returns: the superclass of the class represented by this object
620 *java.lang.Class.getInterfaces()*
622 public native |java.lang.Class| getInterfaces()
624 Determines the interfaces implemented by the class or interface represented by
627 If this object represents a class, the return value is an array containing
628 objects representing all interfaces implemented by the class. The order of the
629 interface objects in the array corresponds to the order of the interface names
630 in the implements clause of the declaration of the class represented by this
631 object. For example, given the declaration:
633 class Shimmer implements FloorWax, DessertTopping { ... }
635 suppose the value of s is an instance of Shimmer; the value of the expression:
637 s.getClass().getInterfaces()[0]
639 is the Class object that represents interface FloorWax; and the value of:
641 s.getClass().getInterfaces()[1]
643 is the Class object that represents interface DessertTopping.
645 If this object represents an interface, the array contains objects representing
646 all interfaces extended by the interface. The order of the interface objects in
647 the array corresponds to the order of the interface names in the extends clause
648 of the declaration of the interface represented by this object.
650 If this object represents a class or interface that implements no interfaces,
651 the method returns an array of length 0.
653 If this object represents a primitive type or void, the method returns an array
657 Returns: an array of interfaces implemented by this class.
658 *java.lang.Class.getMethod(String,Class[])*
660 public |java.lang.reflect.Method| getMethod(
661 java.lang.String name,
662 java.lang.Class[] parameterTypes)
663 throws |java.lang.NoSuchMethodException|
664 |java.lang.SecurityException|
666 Returns a Method object that reflects the specified public member method of the
667 class or interface represented by this Class object. The name parameter is a
668 String specifying the simple name the desired method. The parameterTypes
669 parameter is an array of Class objects that identify the method's formal
670 parameter types, in declared order. If parameterTypes is null, it is treated as
671 if it were an empty array.
673 If the name is "<init>"or "<clinit>" a NoSuchMethodException is raised.
674 Otherwise, the method to be reflected is determined by the algorithm that
675 follows. Let C be the class represented by this object:
677 C is searched for any matching methods. If no matching method is found, the
678 algorithm of step 1 is invoked recursively on the superclass of C. If no method
679 was found in step 1 above, the superinterfaces of C are searched for a matching
680 method. If any such method is found, it is reflected.
682 To find a matching method in a class C: If C declares exactly one public method
683 with the specified name and exactly the same formal parameter types, that is
684 the method reflected. If more than one such method is found in C, and one of
685 these methods has a return type that is more specific than any of the others,
686 that method is reflected; otherwise one of the methods is chosen arbitrarily.
688 See The Java Language Specification, sections 8.2 and 8.4.
690 name - the name of the method
691 parameterTypes - the list of parameters
693 Returns: the Method object that matches the specified name and parameterTypes
694 *java.lang.Class.getMethods()*
696 public |java.lang.reflect.Method| getMethods()
697 throws |java.lang.SecurityException|
699 Returns an array containing Method objects reflecting all the public member
700 methods of the class or interface represented by this Class object, including
701 those declared by the class or interface and those inherited from superclasses
702 and superinterfaces. Array classes return all the (public) member methods
703 inherited from the Object class. The elements in the array returned are not
704 sorted and are not in any particular order. This method returns an array of
705 length 0 if this Class object represents a class or interface that has no
706 public member methods, or if this Class object represents a primitive type or
709 The class initialization method <clinit> is not included in the returned array.
710 If the class declares multiple public member methods with the same parameter
711 types, they are all included in the returned array.
713 See The Java Language Specification, sections 8.2 and 8.4.
716 Returns: the array of Method objects representing the public methods of this class
717 *java.lang.Class.getModifiers()*
719 public native int getModifiers()
721 Returns the Java language modifiers for this class or interface, encoded in an
722 integer. The modifiers consist of the Java Virtual Machine's constants for
723 public, protected, private, final, static, abstract and interface; they should
724 be decoded using the methods of class Modifier.
726 If the underlying class is an array class, then its public, private and
727 protected modifiers are the same as those of its component type. If this Class
728 represents a primitive type or void, its public modifier is always true, and
729 its protected and private modifiers are always false. If this object represents
730 an array class, a primitive type or void, then its final modifier is always
731 true and its interface modifier is always false. The values of its other
732 modifiers are not determined by this specification.
734 The modifier encodings are defined in The Java Virtual Machine Specification,
738 Returns: the int representing the modifiers for this class
739 *java.lang.Class.getName()*
741 public |java.lang.String| getName()
743 Returns the name of the entity (class, interface, array class, primitive type,
744 or void) represented by this Class object, as a String.
746 If this class object represents a reference type that is not an array type then
747 the binary name of the class is returned, as specified by the Java Language
748 Specification, Second Edition.
750 If this class object represents a primitive type or void, then the name
751 returned is a String equal to the Java language keyword corresponding to the
752 primitive type or void.
754 If this class object represents a class of arrays, then the internal form of
755 the name consists of the name of the element type preceded by one or more '['
756 characters representing the depth of the array nesting. The encoding of element
757 type names is as follows:
759 Element Type Encoding boolean Z byte B char C class or interface Lclassname;
760 double D float F int I long J short S
762 The class or interface name classname is the binary name of the class specified
767 String.class.getName() returns "java.lang.String" byte.class.getName() returns
768 "byte" (new Object[3]).getClass().getName() returns "[Ljava.lang.Object;" (new
769 int[3][4][5][6][7][8][9]).getClass().getName() returns "[[[[[[[I"
772 Returns: the name of the class or interface represented by this object.
773 *java.lang.Class.getPackage()*
775 public |java.lang.Package| getPackage()
777 Gets the package for this class. The class loader of this class is used to find
778 the package. If the class was loaded by the bootstrap class loader the set of
779 packages loaded from CLASSPATH is searched to find the package of the class.
780 Null is returned if no package object was created by the class loader of this
783 Packages have attributes for versions and specifications only if the
784 information was defined in the manifests that accompany the classes, and if the
785 class loader created the package instance with the attributes from the
789 Returns: the package of the class, or null if no package information is available from
790 the archive or codebase.
791 *java.lang.Class.getProtectionDomain()*
793 public |java.security.ProtectionDomain| getProtectionDomain()
795 Returns the ProtectionDomain of this class. If there is a security manager
796 installed, this method first calls the security manager's checkPermission
797 method with a RuntimePermission("getProtectionDomain") permission to ensure
798 it's ok to get the ProtectionDomain.
801 Returns: the ProtectionDomain of this class
802 *java.lang.Class.getResource(String)*
804 public |java.net.URL| getResource(java.lang.String name)
806 Finds a resource with a given name. The rules for searching resources
807 associated with a given class are implemented by the defining class
808 loader(|java.lang.ClassLoader|) of the class. This method delegates to this
809 object's class loader. If this object was loaded by the bootstrap class loader,
810 the method delegates to (|java.lang.ClassLoader|) .
812 Before delegation, an absolute resource name is constructed from the given
813 resource name using this algorithm:
817 If the name begins with a '/' ('u002f'), then the absolute name of the resource
818 is the portion of the name following the '/'.
820 Otherwise, the absolute name is of the following form:
824 modified_package_name/name
826 Where the modified_package_name is the package name of this object with '/'
827 substituted for '.' ('u002e').
831 name - name of the desired resource
833 Returns: A {@link java.net.URL} object or null if no resource with this name is found
834 *java.lang.Class.getResourceAsStream(String)*
836 public |java.io.InputStream| getResourceAsStream(java.lang.String name)
838 Finds a resource with a given name. The rules for searching resources
839 associated with a given class are implemented by the defining class
840 loader(|java.lang.ClassLoader|) of the class. This method delegates to this
841 object's class loader. If this object was loaded by the bootstrap class loader,
842 the method delegates to (|java.lang.ClassLoader|) .
844 Before delegation, an absolute resource name is constructed from the given
845 resource name using this algorithm:
849 If the name begins with a '/' ('u002f'), then the absolute name of the resource
850 is the portion of the name following the '/'.
852 Otherwise, the absolute name is of the following form:
856 modified_package_name/name
858 Where the modified_package_name is the package name of this object with '/'
859 substituted for '.' ('u002e').
863 name - name of the desired resource
865 Returns: A {@link java.io.InputStream} object or null if no resource with this name is
867 *java.lang.Class.getSigners()*
869 public native |java.lang.Object| getSigners()
871 Gets the signers of this class.
874 Returns: the signers of this class, or null if there are no signers. In particular, this
875 method returns null if this object represents a primitive type or
877 *java.lang.Class.getSimpleName()*
879 public |java.lang.String| getSimpleName()
881 Returns the simple name of the underlying class as given in the source code.
882 Returns an empty string if the underlying class is anonymous.
884 The simple name of an array is the simple name of the component type with "[]"
885 appended. In particular the simple name of an array whose component type is
889 Returns: the simple name of the underlying class
890 *java.lang.Class.getSuperclass()*
892 public native |java.lang.Class| getSuperclass()
894 Returns the Class representing the superclass of the entity (class, interface,
895 primitive type or void) represented by this Class. If this Class represents
896 either the Object class, an interface, a primitive type, or void, then null is
897 returned. If this object represents an array class then the Class object
898 representing the Object class is returned.
901 Returns: the superclass of the class represented by this object.
902 *java.lang.Class.getTypeParameters()*
904 public |java.lang.reflect.TypeVariable| getTypeParameters()
906 Returns an array of TypeVariable objects that represent the type variables
907 declared by the generic declaration represented by this GenericDeclaration
908 object, in declaration order. Returns an array of length 0 if the underlying
909 generic declaration declares no type variables.
912 Returns: an array of TypeVariable objects that represent the type variables declared by
913 this generic declaration
914 *java.lang.Class.isAnnotation()*
916 public boolean isAnnotation()
918 Returns true if this Class object represents an annotation type. Note that if
919 this method returns true, (|java.lang.Class|) would also return true, as all
920 annotation types are also interfaces.
923 Returns: true if this class object represents an annotation type; false otherwise
924 *java.lang.Class.isAnnotationPresent(Class)*
926 public boolean isAnnotationPresent(java.lang.Class annotationClass)
931 *java.lang.Class.isAnonymousClass()*
933 public boolean isAnonymousClass()
935 Returns true if and only if the underlying class is an anonymous class.
938 Returns: true if and only if this class is an anonymous class.
939 *java.lang.Class.isArray()*
941 public native boolean isArray()
943 Determines if this Class object represents an array class.
946 Returns: true if this object represents an array class; false otherwise.
947 *java.lang.Class.isAssignableFrom(Class)*
949 public native boolean isAssignableFrom(java.lang.Class cls)
951 Determines if the class or interface represented by this Class object is either
952 the same as, or is a superclass or superinterface of, the class or interface
953 represented by the specified Class parameter. It returns true if so; otherwise
954 it returns false. If this Class object represents a primitive type, this method
955 returns true if the specified Class parameter is exactly this Class object;
956 otherwise it returns false.
958 Specifically, this method tests whether the type represented by the specified
959 Class parameter can be converted to the type represented by this Class object
960 via an identity conversion or via a widening reference conversion. See The Java
961 Language Specification, sections 5.1.1 and 5.1.4 , for details.
963 cls - the Class object to be checked
965 Returns: the boolean value indicating whether objects of the type cls can be assigned to
966 objects of this class
967 *java.lang.Class.isEnum()*
969 public boolean isEnum()
971 Returns true if and only if this class was declared as an enum in the source
975 Returns: true if and only if this class was declared as an enum in the source code
976 *java.lang.Class.isInstance(Object)*
978 public native boolean isInstance(java.lang.Object obj)
980 Determines if the specified Object is assignment-compatible with the object
981 represented by this Class. This method is the dynamic equivalent of the Java
982 language instanceof operator. The method returns true if the specified Object
983 argument is non-null and can be cast to the reference type represented by this
984 Class object without raising a ClassCastException. It returns false otherwise.
986 Specifically, if this Class object represents a declared class, this method
987 returns true if the specified Object argument is an instance of the represented
988 class (or of any of its subclasses); it returns false otherwise. If this Class
989 object represents an array class, this method returns true if the specified
990 Object argument can be converted to an object of the array class by an identity
991 conversion or by a widening reference conversion; it returns false otherwise.
992 If this Class object represents an interface, this method returns true if the
993 class or any superclass of the specified Object argument implements this
994 interface; it returns false otherwise. If this Class object represents a
995 primitive type, this method returns false.
997 obj - the object to check
999 Returns: true if obj is an instance of this class
1000 *java.lang.Class.isInterface()*
1002 public native boolean isInterface()
1004 Determines if the specified Class object represents an interface type.
1007 Returns: true if this object represents an interface; false otherwise.
1008 *java.lang.Class.isLocalClass()*
1010 public boolean isLocalClass()
1012 Returns true if and only if the underlying class is a local class.
1015 Returns: true if and only if this class is a local class.
1016 *java.lang.Class.isMemberClass()*
1018 public boolean isMemberClass()
1020 Returns true if and only if the underlying class is a member class.
1023 Returns: true if and only if this class is a member class.
1024 *java.lang.Class.isPrimitive()*
1026 public native boolean isPrimitive()
1028 Determines if the specified Class object represents a primitive type.
1030 There are nine predefined Class objects to represent the eight primitive types
1031 and void. These are created by the Java Virtual Machine, and have the same
1032 names as the primitive types that they represent, namely boolean, byte, char,
1033 short, int, long, float, and double.
1035 These objects may only be accessed via the following public static final
1036 variables, and are the only Class objects for which this method returns true.
1039 Returns: true if and only if this class represents a primitive type
1040 *java.lang.Class.isSynthetic()*
1042 public boolean isSynthetic()
1044 Returns true if this class is a synthetic class; returns false otherwise.
1047 Returns: true if and only if this class is a synthetic class as defined by the Java
1048 Language Specification.
1049 *java.lang.Class.newInstance()*
1051 public |java.lang.Object| newInstance()
1052 throws |java.lang.IllegalAccessException|
1053 |java.lang.InstantiationException|
1055 Creates a new instance of the class represented by this Class object. The class
1056 is instantiated as if by a new expression with an empty argument list. The
1057 class is initialized if it has not already been initialized.
1059 Note that this method propagates any exception thrown by the nullary
1060 constructor, including a checked exception. Use of this method effectively
1061 bypasses the compile-time exception checking that would otherwise be performed
1062 by the compiler. The Constructor.newInstance(|java.lang.reflect.Constructor|)
1063 method avoids this problem by wrapping any exception thrown by the constructor
1064 in a (checked) (|java.lang.reflect.InvocationTargetException|) .
1067 Returns: a newly allocated instance of the class represented by this object.
1068 *java.lang.Class.toString()*
1070 public |java.lang.String| toString()
1072 Converts the object to a string. The string representation is the string
1073 "class" or "interface", followed by a space, and then by the fully qualified
1074 name of the class in the format returned by getName. If this Class object
1075 represents a primitive type, this method returns the name of the primitive
1076 type. If this Class object represents void this method returns "void".
1079 Returns: a string representation of this class object.