Class (Java SE 25 & JDK 25)
- Type Parameters:
T- the type of the class modeled by thisClassobject. For example, the type ofString.classisClass<String>. UseClass<?>if the class being modeled is unknown.
- All Implemented Interfaces:
Serializable, Constable, TypeDescriptor, TypeDescriptor.OfField<Class<?>>, AnnotatedElement, GenericDeclaration, Type
-
Nested Class Summary
-
Method Summary
Returns an unmodifiable set of the access flags for this class, possibly empty.
Returns a
Classfor an array type whose component type is described by this Class.<U> Class<? extends U> Casts this
Classobject to represent a subclass of the class represented by the specified class object.Casts an object to the class or interface represented by this
Classobject.Returns the component type of this
Class, if it describes an array type, ornullotherwise.Returns a nominal descriptor for this instance, if one can be constructed, or an empty
Optionalif one cannot be.Returns the descriptor string of the entity (class, interface, array class, primitive type, or
void) represented by thisClassobject.booleanReturns the assertion status that would be assigned to this class if it were to be initialized at the time this method is invoked.
Returns the
Classwith the given binary name in the given module.Returns the
Classobject associated with the class or interface with the given string name.Returns the
Classobject associated with the class or interface with the given string name, using the given class loader.Returns the
Classobject associated with the primitive type of the given name.Returns an array of
AnnotatedTypeobjects that represent the use of types to specify superinterfaces of the entity represented by thisClassobject.Returns an
AnnotatedTypeobject that represents the use of a type to specify the superclass of the entity represented by thisClassobject.getAnnotation(Class<A> annotationClass) Returns this element's annotation for the specified type if such an annotation is present, else null.
Returns annotations that are present on this element.
getAnnotationsByType(Class<A> annotationClass) Returns annotations that are associated with this element.
Returns the canonical name of the underlying class as defined by The Java Language Specification.
Returns an array containing
Classobjects representing all the public classes and interfaces that are members of the class represented by thisClassobject.Returns the class loader for the class.
Returns the
Classrepresenting the component type of an array.getConstructor(Class<?>... parameterTypes) Returns a
Constructorobject that reflects the specified public constructor of the class represented by thisClassobject.Returns an array containing
Constructorobjects reflecting all the public constructors of the class represented by thisClassobject.getDeclaredAnnotation(Class<A> annotationClass) Returns this element's annotation for the specified type if such an annotation is directly present, else null.
Returns annotations that are directly present on this element.
getDeclaredAnnotationsByType(Class<A> annotationClass) Returns this element's annotation(s) for the specified type if such annotations are either directly present or indirectly present.
Returns an array of
Classobjects reflecting all the classes and interfaces declared as members of the class represented by thisClassobject.getDeclaredConstructor(Class<?>... parameterTypes) Returns a
Constructorobject that reflects the specified constructor of the class represented by thisClassobject.Returns an array of
Constructorobjects reflecting all the constructors implicitly or explicitly declared by the class represented by thisClassobject.Returns a
Fieldobject that reflects the specified declared field of the class or interface represented by thisClassobject.Returns an array of
Fieldobjects reflecting all the fields declared by the class or interface represented by thisClassobject.Returns a
Methodobject that reflects the specified declared method of the class or interface represented by thisClassobject.Returns an array containing
Methodobjects reflecting all the declared methods of the class or interface represented by thisClassobject, including public, protected, default (package) access, and private methods, but excluding inherited methods.If the class or interface represented by this
Classobject is a member of another class, returns theClassobject representing the class in which it was declared.Returns the immediately enclosing class of the underlying class.
If this
Classobject represents a local or anonymous class within a constructor, returns aConstructorobject representing the immediately enclosing constructor of the underlying class.If this
Classobject represents a local or anonymous class within a method, returns aMethodobject representing the immediately enclosing method of the underlying class.T[]Returns the elements of this enum class or null if this Class object does not represent an enum class.
Returns a
Fieldobject that reflects the specified public member field of the class or interface represented by thisClassobject.Returns an array containing
Fieldobjects reflecting all the accessible public fields of the class or interface represented by thisClassobject.Returns the
Types representing the interfaces directly implemented by the class or interface represented by thisClassobject.Returns the
Typerepresenting the direct superclass of the entity (class, interface, primitive type or void) represented by thisClassobject.Returns the interfaces directly implemented by the class or interface represented by this
Classobject.Returns a
Methodobject that reflects the specified public member method of the class or interface represented by thisClassobject.Returns an array containing
Methodobjects reflecting all the public methods of the class or interface represented by thisClassobject, including those declared by the class or interface and those inherited from superclasses and superinterfaces.intReturns the Java language modifiers for this class or interface, encoded in an integer.
Returns the module that this class or interface is a member of.
getName()Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this
Classobject.Returns the nest host of the nest to which the class or interface represented by this
Classobject belongs.Returns an array containing
Classobjects representing all the classes and interfaces that are members of the nest to which the class or interface represented by thisClassobject belongs.Gets the package of this class.
Returns the fully qualified package name.
Returns an array containing
Classobjects representing the direct subinterfaces or subclasses permitted to extend or implement this class or interface if it is sealed.Returns the
ProtectionDomainof this class.Returns an array of
RecordComponentobjects representing all the record components of this record class, ornullif this class is not a record class.Finds a resource with a given name.
Finds a resource with a given name.
Gets the signers of this class.
Returns the simple name of the underlying class as given in the source code.
Returns the
Classrepresenting the direct superclass of the entity (class, interface, primitive type or void) represented by thisClass.Return an informative string for the name of this class or interface.
Returns an array of
TypeVariableobjects that represent the type variables declared by the generic declaration represented by thisGenericDeclarationobject, in declaration order.booleanReturns true if this
Classobject represents an annotation interface.booleanReturns true if an annotation for the specified type is present on this element, else false.
booleanReturns
trueif and only if the underlying class is an anonymous class.booleanisArray()Determines if this
Classobject represents an array class.booleanDetermines if the class or interface represented by this
Classobject is either the same as, or is a superclass or superinterface of, the class or interface represented by the specifiedClassparameter.booleanisEnum()Returns true if and only if this class was declared as an enum in the source code.
booleanisHidden()Returns
trueif and only if the underlying class is a hidden class.booleanDetermines if the specified
Objectis assignment-compatible with the object represented by thisClass.booleanDetermines if this
Classobject represents an interface type.booleanReturns
trueif and only if the underlying class is a local class.booleanReturns
trueif and only if the underlying class is a member class.booleanDetermines if the given
Classis a nestmate of the class or interface represented by thisClassobject.booleanDetermines if this
Classobject represents a primitive type or void.booleanisRecord()Returns
trueif and only if this class is a record class.booleanisSealed()Returns
trueif and only if thisClassobject represents a sealed class or interface.booleanReturns
trueif and only if this class has the synthetic modifier bit set.Returns a string describing this
Class, including information about modifiers,sealed/non-sealedstatus, and type parameters.toString()Converts the object to a string.
-
Method Details
-
toString
-
toGenericString
-
forName
-
forName
-
forName
-
forPrimitiveName
-
newInstance
-
isInstance
-
isAssignableFrom
-
isInterface
-
isArray
-
isPrimitive
-
isAnnotation
-
isSynthetic
-
getName
-
getClassLoader
-
getModule
-
getTypeParameters
-
getSuperclass
-
getGenericSuperclass
-
getPackage
-
getPackageName
-
getInterfaces
-
getGenericInterfaces
-
getComponentType
-
getModifiers
-
accessFlags
-
getSigners
-
getEnclosingMethod
-
getEnclosingConstructor
-
getDeclaringClass
-
getEnclosingClass
-
getSimpleName
-
getTypeName
-
getCanonicalName
-
isAnonymousClass
-
isLocalClass
-
isMemberClass
-
getClasses
-
getFields
-
getMethods
-
getConstructors
-
getField
-
getMethod
-
getConstructor
-
getDeclaredClasses
-
getDeclaredFields
-
getRecordComponents
-
getDeclaredMethods
-
getDeclaredConstructors
-
getDeclaredField
-
getDeclaredMethod
-
getDeclaredConstructor
-
getResourceAsStream
-
getResource
-
getProtectionDomain
-
desiredAssertionStatus
-
isEnum
-
isRecord
-
getEnumConstants
-
cast
-
asSubclass
-
getAnnotation
-
isAnnotationPresent
-
getAnnotationsByType
-
getAnnotations
-
getDeclaredAnnotation
-
getDeclaredAnnotationsByType
-
getDeclaredAnnotations
-
getAnnotatedSuperclass
-
getAnnotatedInterfaces
-
getNestHost
-
isNestmateOf
-
getNestMembers
-
descriptorString
-
componentType
-
arrayType
-
describeConstable
-
isHidden
-
getPermittedSubclasses
-
isSealed
-