1 *java.lang.Class* *Class* Instances of the class Class represent classes and
4 public final class Class<T>
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<U>)|Casts this Class object to represent a su
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<A>)|
25 |java.lang.Class.getAnnotations()|
26 |java.lang.Class.getCanonicalName()|Returns the canonical name of the underlyin
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
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 obje
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
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 ref
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<?extendsAnnotation>)|
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 interfac
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());
106 *java.lang.Class.asSubclass(Class<U>)*
108 public |java.lang.Class|<? extends U> asSubclass(java.lang.Class<U> clazz)
110 Casts this Class object to represent a subclass of the class represented by the
111 specified class object. Checks that that the cast is valid, and throws a
112 ClassCastException if it is not. If this method succeeds, it always returns a
113 reference to this class object.
115 This method is useful when a client needs to "narrow" the type of a Class
116 object to pass it to an API that restricts the Class objects that it is willing
117 to accept. A cast would generate a compile-time warning, as the correctness of
118 the cast could not be checked at runtime (because generic types are implemented
123 Returns: this Class object, cast to represent a subclass of the specified class object.
125 *java.lang.Class.cast(Object)*
127 public |T| cast(java.lang.Object obj)
129 Casts an object to the class or interface represented by this Class object.
132 obj - the object to be cast
134 Returns: the object after casting, or null if obj is null
136 *java.lang.Class.desiredAssertionStatus()*
138 public boolean desiredAssertionStatus()
140 Returns the assertion status that would be assigned to this class if it were to
141 be initialized at the time this method is invoked. If this class has had its
142 assertion status set, the most recent setting will be returned; otherwise, if
143 any package default assertion status pertains to this class, the most recent
144 setting for the most specific pertinent package default assertion status is
145 returned; otherwise, if this class is not a system class (i.e., it has a class
146 loader) its class loader's default assertion status is returned; otherwise, the
147 system class default assertion status is returned.
149 Few programmers will have any need for this method; it is provided for the
150 benefit of the JRE itself. (It allows a class to determine at the time that it
151 is initialized whether assertions should be enabled.) Note that this method is
152 not guaranteed to return the actual assertion status that was (or will be)
153 associated with the specified class when it was (or will be) initialized.
157 Returns: the desired assertion status of the specified class.
159 *java.lang.Class.forName(String)*
161 public static |java.lang.Class|<?> forName(java.lang.String className)
162 throws |java.lang.ClassNotFoundException|
164 Returns the Class object associated with the class or interface with the given
165 string name. Invoking this method is equivalent to:
169 Class.forName(className, true, currentLoader)
171 where currentLoader denotes the defining class loader of the current class.
173 For example, the following code fragment returns the runtime Class descriptor
174 for the class named java.lang.Thread:
178 Classt= Class.forName("java.lang.Thread")
180 A call to forName("X") causes the class named X to be initialized.
183 className - the fully qualified name of the desired class.
185 Returns: the Class object for the class with the specified name.
187 *java.lang.Class.forName(String,boolean,ClassLoader)*
189 public static |java.lang.Class|<?> forName(
190 java.lang.String name,
192 java.lang.ClassLoader loader)
193 throws |java.lang.ClassNotFoundException|
195 Returns the Class object associated with the class or interface with the given
196 string name, using the given class loader. Given the fully qualified name for a
197 class or interface (in the same format returned by getName) this method
198 attempts to locate, load, and link the class or interface. The specified class
199 loader is used to load the class or interface. If the parameter loader is null,
200 the class is loaded through the bootstrap class loader. The class is
201 initialized only if the initialize parameter is true and if it has not been
204 If name denotes a primitive type or void, an attempt will be made to locate a
205 user-defined class in the unnamed package whose name is name. Therefore, this
206 method cannot be used to obtain any of the Class objects representing primitive
209 If name denotes an array class, the component type of the array class is loaded
212 For example, in an instance method the expression:
222 Class.forName("Foo", true, this.getClass().getClassLoader())
224 Note that this method throws errors related to loading, linking or initializing
225 as specified in Sections 12.2, 12.3 and 12.4 of The Java Language
226 Specification. Note that this method does not check whether the requested class
227 is accessible to its caller.
229 If the loader is null, and a security manager is present, and the caller's
230 class loader is not null, then this method calls the security manager's
231 checkPermission method with a RuntimePermission("getClassLoader") permission to
232 ensure it's ok to access the bootstrap class loader.
235 name - fully qualified name of the desired class
236 initialize - whether the class must be initialized
237 loader - class loader from which the class must be loaded
239 Returns: class object representing the desired class
241 *java.lang.Class.getAnnotation(Class<A>)*
243 public |A| getAnnotation(java.lang.Class<A> annotationClass)
249 *java.lang.Class.getAnnotations()*
251 public |java.lang.annotation.Annotation|[] getAnnotations()
257 *java.lang.Class.getCanonicalName()*
259 public |java.lang.String| getCanonicalName()
261 Returns the canonical name of the underlying class as defined by the Java
262 Language Specification. Returns null if the underlying class does not have a
263 canonical name (i.e., if it is a local or anonymous class or an array whose
264 component type does not have a canonical name).
268 Returns: the canonical name of the underlying class if it exists, and null otherwise.
270 *java.lang.Class.getClasses()*
272 public |java.lang.Class|[] getClasses()
274 Returns an array containing Class objects representing all the public classes
275 and interfaces that are members of the class represented by this Class object.
276 This includes public class and interface members inherited from superclasses
277 and public class and interface members declared by the class. This method
278 returns an array of length 0 if this Class object has no public member classes
279 or interfaces. This method also returns an array of length 0 if this Class
280 object represents a primitive type, an array class, or void.
284 Returns: the array of Class objects representing the public members of this class
286 *java.lang.Class.getClassLoader()*
288 public |java.lang.ClassLoader| getClassLoader()
290 Returns the class loader for the class. Some implementations may use null to
291 represent the bootstrap class loader. This method will return null in such
292 implementations if this class was loaded by the bootstrap class loader.
294 If a security manager is present, and the caller's class loader is not null and
295 the caller's class loader is not the same as or an ancestor of the class loader
296 for the class whose class loader is requested, then this method calls the
297 security manager's checkPermission method with a
298 RuntimePermission("getClassLoader") permission to ensure it's ok to access the
299 class loader for the class.
301 If this object represents a primitive type or void, null is returned.
305 Returns: the class loader that loaded the class or interface represented by this object.
307 *java.lang.Class.getComponentType()*
309 public native |java.lang.Class|<?> getComponentType()
311 Returns the Class representing the component type of an array. If this class
312 does not represent an array class this method returns null.
316 Returns: the Class representing the component type of this class if this class is an
319 *java.lang.Class.getConstructor(Class<?>...)*
321 public |java.lang.reflect.Constructor|<T> getConstructor(java.lang.Class[] parameterTypes)
322 throws |java.lang.NoSuchMethodException|
323 |java.lang.SecurityException|
325 Returns a Constructor object that reflects the specified public constructor of
326 the class represented by this Class object. The parameterTypes parameter is an
327 array of Class objects that identify the constructor's formal parameter types,
330 If this Class object represents an inner class declared in a non-static
331 context, the formal parameter types include the explicit enclosing instance as
334 The constructor to reflect is the public constructor of the class represented
335 by this Class object whose formal parameter types match those specified by
339 parameterTypes - the parameter array
341 Returns: the Constructor object of the public constructor that matches the specified
344 *java.lang.Class.getConstructors()*
346 public |java.lang.reflect.Constructor|[] getConstructors()
347 throws |java.lang.SecurityException|
349 Returns an array containing Constructor objects reflecting all the public
350 constructors of the class represented by this Class object. An array of length
351 0 is returned if the class has no public constructors, or if the class is an
352 array class, or if the class reflects a primitive type or void.
354 Note that while this method returns an array ofConstructorobjects (that is an
355 array of constructors from this class), the return type of this method
356 isConstructor[]and notConstructor[]as might be expected. This less informative
357 return type is necessary since after being returned from this method, the array
358 could be modified to holdConstructorobjects for different classes, which would
359 violate the type guarantees ofConstructor[].
363 Returns: the array of Constructor objects representing the public constructors of this
366 *java.lang.Class.getDeclaredAnnotations()*
368 public |java.lang.annotation.Annotation|[] getDeclaredAnnotations()
374 *java.lang.Class.getDeclaredClasses()*
376 public |java.lang.Class|[] getDeclaredClasses()
377 throws |java.lang.SecurityException|
379 Returns an array of Class objects reflecting all the classes and interfaces
380 declared as members of the class represented by this Class object. This
381 includes public, protected, default (package) access, and private classes and
382 interfaces declared by the class, but excludes inherited classes and
383 interfaces. This method returns an array of length 0 if the class declares no
384 classes or interfaces as members, or if this Class object represents a
385 primitive type, an array class, or void.
389 Returns: the array of Class objects representing all the declared members of this class
391 *java.lang.Class.getDeclaredConstructor(Class<?>...)*
393 public |java.lang.reflect.Constructor|<T> getDeclaredConstructor(java.lang.Class[] parameterTypes)
394 throws |java.lang.NoSuchMethodException|
395 |java.lang.SecurityException|
397 Returns a Constructor object that reflects the specified constructor of the
398 class or interface represented by this Class object. The parameterTypes
399 parameter is an array of Class objects that identify the constructor's formal
400 parameter types, in declared order.
402 If this Class object represents an inner class declared in a non-static
403 context, the formal parameter types include the explicit enclosing instance as
407 parameterTypes - the parameter array
409 Returns: The Constructor object for the constructor with the specified parameter list
411 *java.lang.Class.getDeclaredConstructors()*
413 public |java.lang.reflect.Constructor|[] getDeclaredConstructors()
414 throws |java.lang.SecurityException|
416 Returns an array of Constructor objects reflecting all the constructors
417 declared by the class represented by this Class object. These are public,
418 protected, default (package) access, and private constructors. The elements in
419 the array returned are not sorted and are not in any particular order. If the
420 class has a default constructor, it is included in the returned array. This
421 method returns an array of length 0 if this Class object represents an
422 interface, a primitive type, an array class, or void.
424 See The Java Language Specification, section 8.2.
428 Returns: the array of Constructor objects representing all the declared constructors of
431 *java.lang.Class.getDeclaredField(String)*
433 public |java.lang.reflect.Field| getDeclaredField(java.lang.String name)
434 throws |java.lang.NoSuchFieldException|
435 |java.lang.SecurityException|
437 Returns a Field object that reflects the specified declared field of the class
438 or interface represented by this Class object. The name parameter is a String
439 that specifies the simple name of the desired field. Note that this method will
440 not reflect the length field of an array class.
443 name - the name of the field
445 Returns: the Field object for the specified field in this class
447 *java.lang.Class.getDeclaredFields()*
449 public |java.lang.reflect.Field|[] getDeclaredFields()
450 throws |java.lang.SecurityException|
452 Returns an array of Field objects reflecting all the fields declared by the
453 class or interface represented by this Class object. This includes public,
454 protected, default (package) access, and private fields, but excludes inherited
455 fields. The elements in the array returned are not sorted and are not in any
456 particular order. This method returns an array of length 0 if the class or
457 interface declares no fields, or if this Class object represents a primitive
458 type, an array class, or void.
460 See The Java Language Specification, sections 8.2 and 8.3.
464 Returns: the array of Field objects representing all the declared fields of this class
466 *java.lang.Class.getDeclaredMethod(String,Class<?>...)*
468 public |java.lang.reflect.Method| getDeclaredMethod(
469 java.lang.String name,
470 java.lang.Class[] parameterTypes)
471 throws |java.lang.NoSuchMethodException|
472 |java.lang.SecurityException|
474 Returns a Method object that reflects the specified declared method of the
475 class or interface represented by this Class object. The name parameter is a
476 String that specifies the simple name of the desired method, and the
477 parameterTypes parameter is an array of Class objects that identify the
478 method's formal parameter types, in declared order. If more than one method
479 with the same parameter types is declared in a class, and one of these methods
480 has a return type that is more specific than any of the others, that method is
481 returned; otherwise one of the methods is chosen arbitrarily. If the name is
482 "<init>"or "<clinit>" a NoSuchMethodException is raised.
485 name - the name of the method
486 parameterTypes - the parameter array
488 Returns: the Method object for the method of this class matching the specified name and
491 *java.lang.Class.getDeclaredMethods()*
493 public |java.lang.reflect.Method|[] getDeclaredMethods()
494 throws |java.lang.SecurityException|
496 Returns an array of Method objects reflecting all the methods declared by the
497 class or interface represented by this Class object. This includes public,
498 protected, default (package) access, and private methods, but excludes
499 inherited methods. The elements in the array returned are not sorted and are
500 not in any particular order. This method returns an array of length 0 if the
501 class or interface declares no methods, or if this Class object represents a
502 primitive type, an array class, or void. The class initialization method
503 <clinit> is not included in the returned array. If the class declares multiple
504 public member methods with the same parameter types, they are all included in
507 See The Java Language Specification, section 8.2.
511 Returns: the array of Method objects representing all the declared methods of this class
513 *java.lang.Class.getDeclaringClass()*
515 public native |java.lang.Class|<?> getDeclaringClass()
517 If the class or interface represented by this Class object is a member of
518 another class, returns the Class object representing the class in which it was
519 declared. This method returns null if this class or interface is not a member
520 of any other class. If this Class object represents an array class, a primitive
521 type, or void,then this method returns null.
525 Returns: the declaring class for this class
527 *java.lang.Class.getEnclosingClass()*
529 public |java.lang.Class|<?> getEnclosingClass()
531 Returns the immediately enclosing class of the underlying class. If the
532 underlying class is a top level class this method returns null.
536 Returns: the immediately enclosing class of the underlying class
538 *java.lang.Class.getEnclosingConstructor()*
540 public |java.lang.reflect.Constructor|<?> getEnclosingConstructor()
542 If this Class object represents a local or anonymous class within a
543 constructor, returns a Constructor(|java.lang.reflect.Constructor|) object
544 representing the immediately enclosing constructor of the underlying class.
545 Returns null otherwise. In particular, this method returns null if the
546 underlying class is a local or anonymous class immediately enclosed by a type
547 declaration, instance initializer or static initializer.
551 Returns: the immediately enclosing constructor of the underlying class, if that class is
552 a local or anonymous class; otherwise null.
554 *java.lang.Class.getEnclosingMethod()*
556 public |java.lang.reflect.Method| getEnclosingMethod()
558 If this Class object represents a local or anonymous class within a method,
559 returns a Method(|java.lang.reflect.Method|) object representing the
560 immediately enclosing method of the underlying class. Returns null otherwise.
562 In particular, this method returns null if the underlying class is a local or
563 anonymous class immediately enclosed by a type declaration, instance
564 initializer or static initializer.
568 Returns: the immediately enclosing method of the underlying class, if that class is a
569 local or anonymous class; otherwise null.
571 *java.lang.Class.getEnumConstants()*
573 public |T|[] getEnumConstants()
575 Returns the elements of this enum class or null if this Class object does not
576 represent an enum type.
580 Returns: an array containing the values comprising the enum class represented by this
581 Class object in the order they're declared, or null if this Class
582 object does not represent an enum type
584 *java.lang.Class.getField(String)*
586 public |java.lang.reflect.Field| getField(java.lang.String name)
587 throws |java.lang.NoSuchFieldException|
588 |java.lang.SecurityException|
590 Returns a Field object that reflects the specified public member field of the
591 class or interface represented by this Class object. The name parameter is a
592 String specifying the simple name of the desired field.
594 The field to be reflected is determined by the algorithm that follows. Let C be
595 the class represented by this object:
597 If C declares a public field with the name specified, that is the field to be
598 reflected. If no field was found in step 1 above, this algorithm is applied
599 recursively to each direct superinterface of C. The direct superinterfaces are
600 searched in the order they were declared. If no field was found in steps 1 and
601 2 above, and C has a superclass S, then this algorithm is invoked recursively
602 upon S. If C has no superclass, then a NoSuchFieldException is thrown.
604 See The Java Language Specification, sections 8.2 and 8.3.
607 name - the field name
609 Returns: the Field object of this class specified by name
611 *java.lang.Class.getFields()*
613 public |java.lang.reflect.Field|[] getFields()
614 throws |java.lang.SecurityException|
616 Returns an array containing Field objects reflecting all the accessible public
617 fields of the class or interface represented by this Class object. The elements
618 in the array returned are not sorted and are not in any particular order. This
619 method returns an array of length 0 if the class or interface has no accessible
620 public fields, or if it represents an array class, a primitive type, or void.
622 Specifically, if this Class object represents a class, this method returns the
623 public fields of this class and of all its superclasses. If this Class object
624 represents an interface, this method returns the fields of this interface and
625 of all its superinterfaces.
627 The implicit length field for array class is not reflected by this method. User
628 code should use the methods of class Array to manipulate arrays.
630 See The Java Language Specification, sections 8.2 and 8.3.
634 Returns: the array of Field objects representing the public fields
636 *java.lang.Class.getGenericInterfaces()*
638 public |java.lang.reflect.Type|[] getGenericInterfaces()
640 Returns the Types representing the interfaces directly implemented by the class
641 or interface represented by this object.
643 If a superinterface is a parameterized type, the Type object returned for it
644 must accurately reflect the actual type parameters used in the source code. The
645 parameterized type representing each superinterface is created if it had not
646 been created before. See the declaration of
647 ParameterizedType(|java.lang.reflect.ParameterizedType|) for the semantics of
648 the creation process for parameterized types.
650 If this object represents a class, the return value is an array containing
651 objects representing all interfaces implemented by the class. The order of the
652 interface objects in the array corresponds to the order of the interface names
653 in the implements clause of the declaration of the class represented by this
654 object. In the case of an array class, the interfaces Cloneable and
655 Serializable are returned in that order.
657 If this object represents an interface, the array contains objects representing
658 all interfaces directly extended by the interface. The order of the interface
659 objects in the array corresponds to the order of the interface names in the
660 extends clause of the declaration of the interface represented by this object.
662 If this object represents a class or interface that implements no interfaces,
663 the method returns an array of length 0.
665 If this object represents a primitive type or void, the method returns an array
670 Returns: an array of interfaces implemented by this class
672 *java.lang.Class.getGenericSuperclass()*
674 public |java.lang.reflect.Type| getGenericSuperclass()
676 Returns the Type representing the direct superclass of the entity (class,
677 interface, primitive type or void) represented by this Class.
679 If the superclass is a parameterized type, the Type object returned must
680 accurately reflect the actual type parameters used in the source code. The
681 parameterized type representing the superclass is created if it had not been
682 created before. See the declaration of
683 ParameterizedType(|java.lang.reflect.ParameterizedType|) for the semantics of
684 the creation process for parameterized types. If this Class represents either
685 the Object class, an interface, a primitive type, or void, then null is
686 returned. If this object represents an array class then the Class object
687 representing the Object class is returned.
691 Returns: the superclass of the class represented by this object
693 *java.lang.Class.getInterfaces()*
695 public native |java.lang.Class|[] getInterfaces()
697 Determines the interfaces implemented by the class or interface represented by
700 If this object represents a class, the return value is an array containing
701 objects representing all interfaces implemented by the class. The order of the
702 interface objects in the array corresponds to the order of the interface names
703 in the implements clause of the declaration of the class represented by this
704 object. For example, given the declaration:
706 class Shimmer implements FloorWax, DessertTopping { ... }
708 suppose the value of s is an instance of Shimmer; the value of the expression:
710 s.getClass().getInterfaces()[0]
712 is the Class object that represents interface FloorWax; and the value of:
714 s.getClass().getInterfaces()[1]
716 is the Class object that represents interface DessertTopping.
718 If this object represents an interface, the array contains objects representing
719 all interfaces extended by the interface. The order of the interface objects in
720 the array corresponds to the order of the interface names in the extends clause
721 of the declaration of the interface represented by this object.
723 If this object represents a class or interface that implements no interfaces,
724 the method returns an array of length 0.
726 If this object represents a primitive type or void, the method returns an array
731 Returns: an array of interfaces implemented by this class.
733 *java.lang.Class.getMethod(String,Class<?>...)*
735 public |java.lang.reflect.Method| getMethod(
736 java.lang.String name,
737 java.lang.Class[] parameterTypes)
738 throws |java.lang.NoSuchMethodException|
739 |java.lang.SecurityException|
741 Returns a Method object that reflects the specified public member method of the
742 class or interface represented by this Class object. The name parameter is a
743 String specifying the simple name of the desired method. The parameterTypes
744 parameter is an array of Class objects that identify the method's formal
745 parameter types, in declared order. If parameterTypes is null, it is treated as
746 if it were an empty array.
748 If the name is ";"or "" a NoSuchMethodException is raised. Otherwise, the
749 method to be reflected is determined by the algorithm that follows. Let C be
750 the class represented by this object:
752 C is searched for any matching methods. If no matching method is found, the
753 algorithm of step 1 is invoked recursively on the superclass of C. If no method
754 was found in step 1 above, the superinterfaces of C are searched for a matching
755 method. If any such method is found, it is reflected.
757 To find a matching method in a class C: If C declares exactly one public method
758 with the specified name and exactly the same formal parameter types, that is
759 the method reflected. If more than one such method is found in C, and one of
760 these methods has a return type that is more specific than any of the others,
761 that method is reflected; otherwise one of the methods is chosen arbitrarily.
763 Note that there may be more than one matching method in a class because while
764 the Java language forbids a class to declare multiple methods with the same
765 signature but different return types, the Java virtual machine does not. This
766 increased flexibility in the virtual machine can be used to implement various
767 language features. For example, covariant returns can be implemented with
768 bridge methods(|java.lang.reflect.Method|) ; the bridge method and the method
769 being overridden would have the same signature but different return types.
771 See The Java Language Specification, sections 8.2 and 8.4.
774 name - the name of the method
775 parameterTypes - the list of parameters
777 Returns: the Method object that matches the specified name and parameterTypes
779 *java.lang.Class.getMethods()*
781 public |java.lang.reflect.Method|[] getMethods()
782 throws |java.lang.SecurityException|
784 Returns an array containing Method objects reflecting all the public member
785 methods of the class or interface represented by this Class object, including
786 those declared by the class or interface and those inherited from superclasses
787 and superinterfaces. Array classes return all the (public) member methods
788 inherited from the Object class. The elements in the array returned are not
789 sorted and are not in any particular order. This method returns an array of
790 length 0 if this Class object represents a class or interface that has no
791 public member methods, or if this Class object represents a primitive type or
794 The class initialization method <clinit> is not included in the returned array.
795 If the class declares multiple public member methods with the same parameter
796 types, they are all included in the returned array.
798 See The Java Language Specification, sections 8.2 and 8.4.
802 Returns: the array of Method objects representing the public methods of this class
804 *java.lang.Class.getModifiers()*
806 public native int getModifiers()
808 Returns the Java language modifiers for this class or interface, encoded in an
809 integer. The modifiers consist of the Java Virtual Machine's constants for
810 public, protected, private, final, static, abstract and interface; they should
811 be decoded using the methods of class Modifier.
813 If the underlying class is an array class, then its public, private and
814 protected modifiers are the same as those of its component type. If this Class
815 represents a primitive type or void, its public modifier is always true, and
816 its protected and private modifiers are always false. If this object represents
817 an array class, a primitive type or void, then its final modifier is always
818 true and its interface modifier is always false. The values of its other
819 modifiers are not determined by this specification.
821 The modifier encodings are defined in The Java Virtual Machine Specification,
826 Returns: the int representing the modifiers for this class
828 *java.lang.Class.getName()*
830 public |java.lang.String| getName()
832 Returns the name of the entity (class, interface, array class, primitive type,
833 or void) represented by this Class object, as a String.
835 If this class object represents a reference type that is not an array type then
836 the binary name of the class is returned, as specified by the Java Language
837 Specification, Second Edition.
839 If this class object represents a primitive type or void, then the name
840 returned is a String equal to the Java language keyword corresponding to the
841 primitive type or void.
843 If this class object represents a class of arrays, then the internal form of
844 the name consists of the name of the element type preceded by one or more '['
845 characters representing the depth of the array nesting. The encoding of element
846 type names is as follows:
848 Element Type Encoding boolean Z byte B char C class or interface Lclassname;
849 double D float F int I long J short S
851 The class or interface name classname is the binary name of the class specified
856 String.class.getName() returns "java.lang.String" byte.class.getName() returns
857 "byte" (new Object[3]).getClass().getName() returns "[Ljava.lang.Object;" (new
858 int[3][4][5][6][7][8][9]).getClass().getName() returns "[[[[[[[I"
862 Returns: the name of the class or interface represented by this object.
864 *java.lang.Class.getPackage()*
866 public |java.lang.Package| getPackage()
868 Gets the package for this class. The class loader of this class is used to find
869 the package. If the class was loaded by the bootstrap class loader the set of
870 packages loaded from CLASSPATH is searched to find the package of the class.
871 Null is returned if no package object was created by the class loader of this
874 Packages have attributes for versions and specifications only if the
875 information was defined in the manifests that accompany the classes, and if the
876 class loader created the package instance with the attributes from the
881 Returns: the package of the class, or null if no package information is available from
882 the archive or codebase.
884 *java.lang.Class.getProtectionDomain()*
886 public |java.security.ProtectionDomain| getProtectionDomain()
888 Returns the ProtectionDomain of this class. If there is a security manager
889 installed, this method first calls the security manager's checkPermission
890 method with a RuntimePermission("getProtectionDomain") permission to ensure
891 it's ok to get the ProtectionDomain.
895 Returns: the ProtectionDomain of this class
897 *java.lang.Class.getResource(String)*
899 public |java.net.URL| getResource(java.lang.String name)
901 Finds a resource with a given name. The rules for searching resources
902 associated with a given class are implemented by the defining class
903 loader(|java.lang.ClassLoader|) of the class. This method delegates to this
904 object's class loader. If this object was loaded by the bootstrap class loader,
905 the method delegates to (|java.lang.ClassLoader|) .
907 Before delegation, an absolute resource name is constructed from the given
908 resource name using this algorithm:
912 If the name begins with a '/' ('u002f'), then the absolute name of the resource
913 is the portion of the name following the '/'.
915 Otherwise, the absolute name is of the following form:
919 modified_package_name/name
921 Where the modified_package_name is the package name of this object with '/'
922 substituted for '.' ('u002e').
927 name - name of the desired resource
929 Returns: A {@link java.net.URL} object or null if no resource with this name is found
931 *java.lang.Class.getResourceAsStream(String)*
933 public |java.io.InputStream| getResourceAsStream(java.lang.String name)
935 Finds a resource with a given name. The rules for searching resources
936 associated with a given class are implemented by the defining class
937 loader(|java.lang.ClassLoader|) of the class. This method delegates to this
938 object's class loader. If this object was loaded by the bootstrap class loader,
939 the method delegates to (|java.lang.ClassLoader|) .
941 Before delegation, an absolute resource name is constructed from the given
942 resource name using this algorithm:
946 If the name begins with a '/' ('u002f'), then the absolute name of the resource
947 is the portion of the name following the '/'.
949 Otherwise, the absolute name is of the following form:
953 modified_package_name/name
955 Where the modified_package_name is the package name of this object with '/'
956 substituted for '.' ('u002e').
961 name - name of the desired resource
963 Returns: A {@link java.io.InputStream} object or null if no resource with this name is
966 *java.lang.Class.getSigners()*
968 public native |java.lang.Object|[] getSigners()
970 Gets the signers of this class.
974 Returns: the signers of this class, or null if there are no signers. In particular, this
975 method returns null if this object represents a primitive type or
978 *java.lang.Class.getSimpleName()*
980 public |java.lang.String| getSimpleName()
982 Returns the simple name of the underlying class as given in the source code.
983 Returns an empty string if the underlying class is anonymous.
985 The simple name of an array is the simple name of the component type with "[]"
986 appended. In particular the simple name of an array whose component type is
991 Returns: the simple name of the underlying class
993 *java.lang.Class.getSuperclass()*
995 public native |java.lang.Class|<? super T> getSuperclass()
997 Returns the Class representing the superclass of the entity (class, interface,
998 primitive type or void) represented by this Class. If this Class represents
999 either the Object class, an interface, a primitive type, or void, then null is
1000 returned. If this object represents an array class then the Class object
1001 representing the Object class is returned.
1005 Returns: the superclass of the class represented by this object.
1007 *java.lang.Class.getTypeParameters()*
1009 public |java.lang.reflect.TypeVariable|[] getTypeParameters()
1011 Returns an array of TypeVariable objects that represent the type variables
1012 declared by the generic declaration represented by this GenericDeclaration
1013 object, in declaration order. Returns an array of length 0 if the underlying
1014 generic declaration declares no type variables.
1018 Returns: an array of TypeVariable objects that represent the type variables declared by
1019 this generic declaration
1021 *java.lang.Class.isAnnotation()*
1023 public boolean isAnnotation()
1025 Returns true if this Class object represents an annotation type. Note that if
1026 this method returns true, (|java.lang.Class|) would also return true, as all
1027 annotation types are also interfaces.
1031 Returns: true if this class object represents an annotation type; false otherwise
1033 *java.lang.Class.isAnnotationPresent(Class<?extendsAnnotation>)*
1035 public boolean isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
1041 *java.lang.Class.isAnonymousClass()*
1043 public boolean isAnonymousClass()
1045 Returns true if and only if the underlying class is an anonymous class.
1049 Returns: true if and only if this class is an anonymous class.
1051 *java.lang.Class.isArray()*
1053 public native boolean isArray()
1055 Determines if this Class object represents an array class.
1059 Returns: true if this object represents an array class; false otherwise.
1061 *java.lang.Class.isAssignableFrom(Class<?>)*
1063 public native boolean isAssignableFrom(java.lang.Class<?> cls)
1065 Determines if the class or interface represented by this Class object is either
1066 the same as, or is a superclass or superinterface of, the class or interface
1067 represented by the specified Class parameter. It returns true if so; otherwise
1068 it returns false. If this Class object represents a primitive type, this method
1069 returns true if the specified Class parameter is exactly this Class object;
1070 otherwise it returns false.
1072 Specifically, this method tests whether the type represented by the specified
1073 Class parameter can be converted to the type represented by this Class object
1074 via an identity conversion or via a widening reference conversion. See The Java
1075 Language Specification, sections 5.1.1 and 5.1.4 , for details.
1078 cls - the Class object to be checked
1080 Returns: the boolean value indicating whether objects of the type cls can be assigned to
1081 objects of this class
1083 *java.lang.Class.isEnum()*
1085 public boolean isEnum()
1087 Returns true if and only if this class was declared as an enum in the source
1092 Returns: true if and only if this class was declared as an enum in the source code
1094 *java.lang.Class.isInstance(Object)*
1096 public native boolean isInstance(java.lang.Object obj)
1098 Determines if the specified Object is assignment-compatible with the object
1099 represented by this Class. This method is the dynamic equivalent of the Java
1100 language instanceof operator. The method returns true if the specified Object
1101 argument is non-null and can be cast to the reference type represented by this
1102 Class object without raising a ClassCastException. It returns false otherwise.
1104 Specifically, if this Class object represents a declared class, this method
1105 returns true if the specified Object argument is an instance of the represented
1106 class (or of any of its subclasses); it returns false otherwise. If this Class
1107 object represents an array class, this method returns true if the specified
1108 Object argument can be converted to an object of the array class by an identity
1109 conversion or by a widening reference conversion; it returns false otherwise.
1110 If this Class object represents an interface, this method returns true if the
1111 class or any superclass of the specified Object argument implements this
1112 interface; it returns false otherwise. If this Class object represents a
1113 primitive type, this method returns false.
1116 obj - the object to check
1118 Returns: true if obj is an instance of this class
1120 *java.lang.Class.isInterface()*
1122 public native boolean isInterface()
1124 Determines if the specified Class object represents an interface type.
1128 Returns: true if this object represents an interface; false otherwise.
1130 *java.lang.Class.isLocalClass()*
1132 public boolean isLocalClass()
1134 Returns true if and only if the underlying class is a local class.
1138 Returns: true if and only if this class is a local class.
1140 *java.lang.Class.isMemberClass()*
1142 public boolean isMemberClass()
1144 Returns true if and only if the underlying class is a member class.
1148 Returns: true if and only if this class is a member class.
1150 *java.lang.Class.isPrimitive()*
1152 public native boolean isPrimitive()
1154 Determines if the specified Class object represents a primitive type.
1156 There are nine predefined Class objects to represent the eight primitive types
1157 and void. These are created by the Java Virtual Machine, and have the same
1158 names as the primitive types that they represent, namely boolean, byte, char,
1159 short, int, long, float, and double.
1161 These objects may only be accessed via the following public static final
1162 variables, and are the only Class objects for which this method returns true.
1166 Returns: true if and only if this class represents a primitive type
1168 *java.lang.Class.isSynthetic()*
1170 public boolean isSynthetic()
1172 Returns true if this class is a synthetic class; returns false otherwise.
1176 Returns: true if and only if this class is a synthetic class as defined by the Java
1177 Language Specification.
1179 *java.lang.Class.newInstance()*
1181 public |T| newInstance()
1182 throws |java.lang.IllegalAccessException|
1183 |java.lang.InstantiationException|
1185 Creates a new instance of the class represented by this Class object. The class
1186 is instantiated as if by a new expression with an empty argument list. The
1187 class is initialized if it has not already been initialized.
1189 Note that this method propagates any exception thrown by the nullary
1190 constructor, including a checked exception. Use of this method effectively
1191 bypasses the compile-time exception checking that would otherwise be performed
1192 by the compiler. The Constructor.newInstance(|java.lang.reflect.Constructor|)
1193 method avoids this problem by wrapping any exception thrown by the constructor
1194 in a (checked) (|java.lang.reflect.InvocationTargetException|) .
1198 Returns: a newly allocated instance of the class represented by this object.
1200 *java.lang.Class.toString()*
1202 public |java.lang.String| toString()
1204 Converts the object to a string. The string representation is the string
1205 "class" or "interface", followed by a space, and then by the fully qualified
1206 name of the class in the format returned by getName. If this Class object
1207 represents a primitive type, this method returns the name of the primitive
1208 type. If this Class object represents void this method returns "void".
1212 Returns: a string representation of this class object.