- All Implemented Interfaces:
Serializable
,Constable
,TypeDescriptor
,TypeDescriptor.OfField<Class<?>>
,AnnotatedElement
,GenericDeclaration
,Type
- Classes representing object types (classes or interfaces)
- These are Classes which represent the class of a simple instance as found in the class hierarchy. The name of one of these Classes is simply the fully qualified class name of the class or interface that it represents. Its signature is the letter "L", followed by its name, followed by a semi-colon (";").
- Classes representing base types
- These Classes represent the standard Java base types.
Although it is not possible to create new instances
of these Classes, they are still useful for providing
reflection information, and as the component type
of array classes. There is one of these Classes for
each base type, and their signatures are:
B
representing thebyte
base typeS
representing theshort
base typeI
representing theint
base typeJ
representing thelong
base typeF
representing thefloat
base typeD
representing thedouble
base typeC
representing thechar
base typeZ
representing theboolean
base typeV
representing void function return values
int
base type. - Classes representing array classes
- These are Classes which represent the classes of Java arrays. There is one such Class for all array instances of a given arity (number of dimensions) and leaf component type. In this case, the name of the class is one or more left square brackets (one per dimension in the array) followed by the signature ofP the class representing the leaf component type, which can be either an object type or a base type. The signature of a Class representing an array type is the same as its name.
- See Also:
-
Nested Class Summary
Nested classes/interfaces declared in interface java.lang.invoke.TypeDescriptor
TypeDescriptor.OfField<F extends TypeDescriptor.OfField<F>>, TypeDescriptor.OfMethod<F extends TypeDescriptor.OfField<F>,
M extends TypeDescriptor.OfMethod<F, M>> -
Method Summary
Modifier and TypeMethodDescriptionClass<?>
Create class of an array.<U> Class<? extends U>
asSubclass
(Class<U> cls) Cast this Class to a subclass of the specified Class.Cast the specified object to this Class.Class<?>
Answers a Class object which represents the receiver's component type if the receiver represents an array type.Returns the nominal descriptor of this Class instance, or an empty Optional if construction is not possible.Return field descriptor of Class instance.boolean
Returns the assertion status for this class.static Class<?>
Answers a Class object which represents the class with the given name in the given module.static Class<?>
Answers a Class object which represents the class named by the argument.static Class<?>
forName
(String className, boolean initializeBoolean, ClassLoader classLoader) Answers a Class object which represents the class named by the argument.Return the annotated types for the implemented interfaces.Return the annotated superclass of this class.<A extends Annotation>
AgetAnnotation
(Class<A> annotation) Return the specified Annotation for this Class.Return the directly declared Annotations for this Class, including the Annotations inherited from superclasses.<A extends Annotation>
A[]getAnnotationsByType
(Class<A> annotationClass) Gets the specified type annotations of this class.Return the canonical name of this Class.Class<?>[]
Answers an array containing all public class members of the class which the receiver represents and its superclasses and interfacesAnswers the classloader which was used to load the class represented by the receiver.Class<?>
Answers a Class object which represents the receiver's component type if the receiver represents an array type.getConstructor
(Class<?>... parameterTypes) Answers a public Constructor object which represents the constructor described by the arguments.Constructor<?>[]
Answers an array containing Constructor objects describing all constructors which are visible from the current execution context.<A extends Annotation>
AgetDeclaredAnnotation
(Class<A> annotation) Looks through directly declared annotations for this class, not including Annotations inherited from superclasses.Returns the annotations only for this Class, not including Annotations inherited from superclasses.<A extends Annotation>
A[]getDeclaredAnnotationsByType
(Class<A> annotationClass) Gets the specified type annotations of this class.Class<?>[]
Answers an array containing all class members of the class which the receiver represents.getDeclaredConstructor
(Class<?>... parameterTypes) Answers a Constructor object which represents the constructor described by the arguments.Constructor<?>[]
Answers an array containing Constructor objects describing all constructor which are defined by the receiver.getDeclaredField
(String name) Answers a Field object describing the field in the receiver named by the argument.Field[]
Answers an array containing Field objects describing all fields which are defined by the receiver.getDeclaredMethod
(String name, Class<?>... parameterTypes) Answers a Method object which represents the method described by the arguments.Method[]
Answers an array containing Method objects describing all methods which are defined by the receiver.Class<?>
Answers the class which declared the class represented by the receiver.Class<?>
Return the enclosing Class of this Class.Constructor<?>
If this Class is defined inside a constructor, return the Constructor.If this Class is defined inside a method, return the Method.T[]
Answer the array of enum constants for this Class.Answers a Field object describing the field in the receiver named by the argument which must be visible from the current execution context.Field[]
Answers an array containing Field objects describing all fields which are visible from the current execution context.Type[]
Answers an array of Type for the Class objects which match the interfaces specified in the receiver classesimplements
declaration.Answers the Type for the Class which represents the receiver's superclass.Class<?>[]
Answers an array of Class objects which match the interfaces specified in the receiver classesimplements
declarationAnswers a Method object which represents the method described by the arguments.Method[]
Answers an array containing Method objects describing all methods which are visible from the current execution context.int
Answers an integer which is the receiver's modifiers.Answers the module to which the receiver belongs.getName()
Answers the name of the class which the receiver represents.Class<?>
Answers the host class of the receiver's nest.Class<?>[]
Answers the nest member classes of the receiver's nest host.Returns the Package of which this class is a member.Answers the name of the package to which the receiver belongs.Class<?>[]
Returns the permitted subclasses related to the calling sealed class as an array of Class objects.Answers the ProtectionDomain of the receiver.Returns an array of RecordComponent objects for a record class.getResource
(String resName) Answers a URL referring to the resource specified by resName.getResourceAsStream
(String resName) Answers a read-only stream on the contents of the resource specified by resName.Object[]
Answers the signers for the class represented by the receiver, or null if there are no signers.Return the simple name of this Class.Answers the Class which represents the receiver's superclass.Answers the type name of the class which the receiver represents.TypeVariable<Class<T>>[]
Answers an array of TypeVariable for the generic parameters declared on this Class.boolean
Answer if this class is an Annotation.boolean
isAnnotationPresent
(Class<? extends Annotation> annotation) Answer if the specified Annotation exists for this Class.boolean
Answer if this Class is anonymous.boolean
isArray()
Answers true if the receiver represents an array class.boolean
isAssignableFrom
(Class<?> cls) Answers true if the type represented by the argument can be converted via an identity conversion or a widening reference conversion (i.e. if either the receiver or the argument represent primitive types, only the identity conversion applies).boolean
isEnum()
Answer if this Class is an enum.boolean
isHidden()
Returns true if the class is a hidden class.boolean
isInstance
(Object object) Answers true if the argument is non-null and can be cast to the type of the receiver.boolean
Answers true if the receiver represents an interface.boolean
Answer if this Class is local.boolean
Answer if this Class is a member Class.boolean
isNestmateOf
(Class<?> that) Returns true if the class passed has the same nest top as this class.boolean
Answers true if the receiver represents a base type.boolean
isRecord()
Returns true if the class instance is a record.boolean
isSealed()
Returns true if class or interface is sealed.boolean
Answer if this Class is synthetic.Deprecated.Returns a formatted string describing this Class.toString()
Answers a string containing a concise, human-readable description of the receiver.
-
Method Details
-
forName
Answers a Class object which represents the class named by the argument. The name should be the name of a class as described in the class definition of java.lang.Class, however Classes representing base types can not be found using this method.- Parameters:
className
- The name of the non-base type class to find- Returns:
- the named Class
- Throws:
ClassNotFoundException
- If the class could not be found- See Also:
-
forName
public static Class<?> forName(String className, boolean initializeBoolean, ClassLoader classLoader) throws ClassNotFoundException Answers a Class object which represents the class named by the argument. The name should be the name of a class as described in the class definition of java.lang.Class, however Classes representing base types can not be found using this method. Security rules will be obeyed.- Parameters:
className
- The name of the non-base type class to findinitializeBoolean
- A boolean indicating whether the class should be initializedclassLoader
- The classloader to use to load the class- Returns:
- the named class.
- Throws:
ClassNotFoundException
- If the class could not be found- See Also:
-
forName
Answers a Class object which represents the class with the given name in the given module. The name should be the name of a class as described in the class definition of java.lang.Class, however Classes representing base types can not be found using this method. It does not invoke the class initializer. Note that this method does not check whether the requested class is accessible to its caller. Security rules will be obeyed.- Parameters:
module
- The name of the modulename
- The name of the non-base type class to find- Returns:
- The Class object representing the named class
- See Also:
-
getClasses
Answers an array containing all public class members of the class which the receiver represents and its superclasses and interfaces- Returns:
- the class' public class members
- Throws:
SecurityException
- If member access is not allowed- See Also:
-
getClassLoader
Answers the classloader which was used to load the class represented by the receiver. Answer null if the class was loaded by the system class loader.- Returns:
- the receiver's class loader or nil
- See Also:
-
getComponentType
Answers a Class object which represents the receiver's component type if the receiver represents an array type. Otherwise answers nil. The component type of an array type is the type of the elements of the array.- Returns:
- the component type of the receiver.
- See Also:
-
getConstructor
public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException Answers a public Constructor object which represents the constructor described by the arguments.- Parameters:
parameterTypes
- the types of the arguments.- Returns:
- the constructor described by the arguments.
- Throws:
NoSuchMethodException
- if the constructor could not be found.SecurityException
- if member access is not allowed- See Also:
-
getConstructors
Answers an array containing Constructor objects describing all constructors which are visible from the current execution context.- Returns:
- all visible constructors starting from the receiver.
- Throws:
SecurityException
- if member access is not allowed- See Also:
-
getDeclaredClasses
Answers an array containing all class members of the class which the receiver represents. Note that some of the fields which are returned may not be visible in the current execution context.- Returns:
- the class' class members
- Throws:
SecurityException
- if member access is not allowed- See Also:
-
getDeclaredConstructor
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException Answers a Constructor object which represents the constructor described by the arguments.- Parameters:
parameterTypes
- the types of the arguments.- Returns:
- the constructor described by the arguments.
- Throws:
NoSuchMethodException
- if the constructor could not be found.SecurityException
- if member access is not allowed- See Also:
-
getDeclaredConstructors
Answers an array containing Constructor objects describing all constructor which are defined by the receiver. Note that some of the fields which are returned may not be visible in the current execution context.- Returns:
- the receiver's constructors.
- Throws:
SecurityException
- if member access is not allowed- See Also:
-
getDeclaredField
Answers a Field object describing the field in the receiver named by the argument. Note that the Constructor may not be visible from the current execution context.- Parameters:
name
- The name of the field to look for.- Returns:
- the field in the receiver named by the argument.
- Throws:
NoSuchFieldException
- if the requested field could not be foundSecurityException
- if member access is not allowed- See Also:
-
getDeclaredFields
Answers an array containing Field objects describing all fields which are defined by the receiver. Note that some of the fields which are returned may not be visible in the current execution context.- Returns:
- the receiver's fields.
- Throws:
SecurityException
- If member access is not allowed- See Also:
-
getDeclaredMethod
public Method getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException Answers a Method object which represents the method described by the arguments. Note that the associated method may not be visible from the current execution context.- Parameters:
name
- the name of the methodparameterTypes
- the types of the arguments.- Returns:
- the method described by the arguments.
- Throws:
NoSuchMethodException
- if the method could not be found.SecurityException
- If member access is not allowed- See Also:
-
getDeclaredMethods
Answers an array containing Method objects describing all methods which are defined by the receiver. Note that some of the methods which are returned may not be visible in the current execution context.- Returns:
- the receiver's methods.
- Throws:
SecurityException
- if member access is not allowed- See Also:
-
getDeclaringClass
Answers the class which declared the class represented by the receiver. This will return null if the receiver is not a member of another class.- Returns:
- the declaring class of the receiver.
-
getField
Answers a Field object describing the field in the receiver named by the argument which must be visible from the current execution context.- Parameters:
name
- The name of the field to look for.- Returns:
- the field in the receiver named by the argument.
- Throws:
NoSuchFieldException
- If the given field does not existSecurityException
- If access is denied- See Also:
-
getFields
Answers an array containing Field objects describing all fields which are visible from the current execution context.- Returns:
- all visible fields starting from the receiver.
- Throws:
SecurityException
- If member access is not allowed- See Also:
-
getInterfaces
Answers an array of Class objects which match the interfaces specified in the receiver classesimplements
declaration- Returns:
Class<?>[]
the interfaces the receiver claims to implement.
-
getMethod
public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException Answers a Method object which represents the method described by the arguments.- Parameters:
name
- String the name of the methodparameterTypes
-Class<?>[]
the types of the arguments.- Returns:
- Method the method described by the arguments.
- Throws:
NoSuchMethodException
- if the method could not be found.SecurityException
- if member access is not allowed- See Also:
-
getMethods
Answers an array containing Method objects describing all methods which are visible from the current execution context.- Returns:
- Method[] all visible methods starting from the receiver.
- Throws:
SecurityException
- if member access is not allowed- See Also:
-
getModifiers
public int getModifiers()Answers an integer which is the receiver's modifiers. Note that the constants which describe the bits which are returned are implemented in class java.lang.reflect.Modifier which may not be available on the target.- Returns:
- the receiver's modifiers
-
getModule
Answers the module to which the receiver belongs. If this class doesn't belong to a named module, the unnamedModule of the classloader loaded this class is returned; If this class represents an array type, the module for the element type is returned; If this class represents a primitive type or void, module java.base is returned.- Returns:
- the module to which the receiver belongs
-
getName
Answers the name of the class which the receiver represents. For a description of the format which is used, see the class definition of java.lang.Class.- Returns:
- the receiver's name.
- See Also:
-
getProtectionDomain
Answers the ProtectionDomain of the receiver.Note: In order to conserve space in embedded targets, we allow this method to answer null for classes in the system protection domain (i.e. for system classes). System classes are always given full permissions (i.e. AllPermission). This is not changeable via the java.security.Policy.
- Returns:
- ProtectionDomain the receiver's ProtectionDomain.
- See Also:
-
getPackageName
Answers the name of the package to which the receiver belongs. For example, Object.class.getPackageName() returns "java.lang". Returns "java.lang" if this class represents a primitive type or void, and the element type's package name in the case of an array type.- Returns:
- String the receiver's package name
- See Also:
-
getResource
Answers a URL referring to the resource specified by resName. The mapping between the resource name and the URL is managed by the class's class loader.- Parameters:
resName
- the name of the resource.- Returns:
- a stream on the resource.
- See Also:
-
getResourceAsStream
Answers a read-only stream on the contents of the resource specified by resName. The mapping between the resource name and the stream is managed by the class's class loader.- Parameters:
resName
- the name of the resource.- Returns:
- a stream on the resource.
- See Also:
-
getSigners
Answers the signers for the class represented by the receiver, or null if there are no signers.- Returns:
- the signers of the receiver.
- See Also:
-
getSuperclass
Answers the Class which represents the receiver's superclass. For Classes which represent base types, interfaces, and for java.lang.Object the method answers null.- Returns:
- the receiver's superclass.
-
isArray
public boolean isArray()Answers true if the receiver represents an array class.- Specified by:
isArray
in interfaceTypeDescriptor.OfField<T>
- Returns:
true
if the receiver represents an array classfalse
if it does not represent an array class
-
isAssignableFrom
Answers true if the type represented by the argument can be converted via an identity conversion or a widening reference conversion (i.e. if either the receiver or the argument represent primitive types, only the identity conversion applies).- Parameters:
cls
- Class the class to test- Returns:
true
the argument can be assigned into the receiverfalse
the argument cannot be assigned into the receiver- Throws:
NullPointerException
- if the parameter is null
-
isInstance
Answers true if the argument is non-null and can be cast to the type of the receiver. This is the runtime version of theinstanceof
operator.- Parameters:
object
- Object the object to test- Returns:
true
the argument can be cast to the type of the receiverfalse
the argument is null or cannot be cast to the type of the receiver
-
isInterface
public boolean isInterface()Answers true if the receiver represents an interface.- Returns:
true
if the receiver represents an interfacefalse
if it does not represent an interface
-
isPrimitive
public boolean isPrimitive()Answers true if the receiver represents a base type.- Specified by:
isPrimitive
in interfaceTypeDescriptor.OfField<T>
- Returns:
true
if the receiver represents a base typefalse
if it does not represent a base type
-
newInstance
@Deprecated(forRemoval=false, since="9") public T newInstance() throws IllegalAccessException, InstantiationExceptionDeprecated.Answers a new instance of the class represented by the receiver, created by invoking the default (i.e. zero-argument) constructor. If there is no such constructor, or if the creation fails (either because of a lack of available memory or because an exception is thrown by the constructor), an InstantiationException is thrown. If the default constructor exists, but is not accessible from the context where this message is sent, an IllegalAccessException is thrown.- Returns:
- a new instance of the class represented by the receiver.
- Throws:
IllegalAccessException
- if the constructor is not visible to the sender.InstantiationException
- if the instance could not be created.
-
toString
Answers a string containing a concise, human-readable description of the receiver. -
toGenericString
Returns a formatted string describing this Class. The string has the following format: modifier1 modifier2 ... kind name<typeparam1, typeparam2, ...>. kind is one ofclass
,enum
,interface
,@interface
, or the empty string for primitive types. The type parameter list is omitted if there are no type parameters. For array classes, the string has the following format instead: name<typeparam1, typeparam2, ...> followed by a number of[]
pairs, one pair for each dimension of the array.- Returns:
- a formatted string describing this class
- Since:
- 1.8
-
getPackage
Returns the Package of which this class is a member. A class has a Package iff it was loaded from a SecureClassLoader.- Returns:
- Package the Package of which this class is a member or null in the case of primitive or array types
-
desiredAssertionStatus
public boolean desiredAssertionStatus()Returns the assertion status for this class. Assertion is enabled/disabled based on classloader default, package or class default at runtime- Returns:
- the assertion status for this class
- Since:
- 1.4
-
getAnnotation
Return the specified Annotation for this Class. Inherited Annotations are searched.- Specified by:
getAnnotation
in interfaceAnnotatedElement
- Type Parameters:
A
- the type of the annotation to query for and return if present- Parameters:
annotation
- the Annotation type- Returns:
- the specified Annotation or null
- Since:
- 1.5
-
getAnnotations
Return the directly declared Annotations for this Class, including the Annotations inherited from superclasses. If an annotation type has been included before, then next occurrences will not be included. Repeated annotations are not included since they will be stored in their container annotation. But container annotations are included. (If a container annotation is repeatable and it is repeated, then these container annotations' container annotation is included. )- Specified by:
getAnnotations
in interfaceAnnotatedElement
- Returns:
- an array of Annotation
- Since:
- 1.5
-
getDeclaredAnnotation
Looks through directly declared annotations for this class, not including Annotations inherited from superclasses.- Specified by:
getDeclaredAnnotation
in interfaceAnnotatedElement
- Type Parameters:
A
- the type of the annotation to query for and return if directly present- Parameters:
annotation
- the Annotation to search for- Returns:
- directly declared annotation of specified annotation type.
- Since:
- 1.8
-
getAnnotatedInterfaces
Return the annotated types for the implemented interfaces.- Returns:
- array, possibly empty, of AnnotatedTypes
-
getAnnotatedSuperclass
Return the annotated superclass of this class.- Returns:
- null if this class is Object, an interface, a primitive type, or an array type. Otherwise return (possibly empty) AnnotatedType.
-
getTypeName
Answers the type name of the class which the receiver represents.- Specified by:
getTypeName
in interfaceType
- Returns:
- the fully qualified type name, with brackets if an array class
- Since:
- 1.8
-
getDeclaredAnnotations
Returns the annotations only for this Class, not including Annotations inherited from superclasses. It includes all the directly declared annotations. Repeated annotations are not included but their container annotation does.- Specified by:
getDeclaredAnnotations
in interfaceAnnotatedElement
- Returns:
- an array of declared annotations
- Since:
- 1.5
-
getDeclaredAnnotationsByType
Gets the specified type annotations of this class.
Terms used for annotations :
Repeatable Annotation :An annotation which can be used more than once for the same class declaration. Repeatable annotations are annotated with Repeatable annotation which tells the container annotation for this repeatable annotation.
Example
Container Annotation:@interface ContainerAnnotation {RepeatableAnn[] value();} @Repeatable(ContainerAnnotation.class)
Container annotation stores the repeated annotations in its array-valued element. Using repeatable annotations more than once makes them stored in their container annotation. In this case, container annotation is visible directly on class declaration, but not the repeated annotations.
Repeated Annotation:A repeatable annotation which is used more than once for the same class.
Directly Declared Annotation :All non repeatable annotations are directly declared annotations. As for repeatable annotations, they can be directly declared annotation if and only if they are used once. Repeated annotations are not directly declared in class declaration, but their container annotation does.
-------------------------------------------------------------------------------------------------------If the specified type is not repeatable annotation, then returned array size will be 0 or 1. If specified type is repeatable annotation, then all the annotations of that type will be returned. Array size might be 0, 1 or more.
It does not search through super classes.- Specified by:
getDeclaredAnnotationsByType
in interfaceAnnotatedElement
- Type Parameters:
A
- the type of the annotation to query for and return if directly or indirectly present- Parameters:
annotationClass
- the annotation type to search for- Returns:
- array of declared annotations in the specified annotation type
- Since:
- 1.8
-
getAnnotationsByType
Gets the specified type annotations of this class. If the specified type is not repeatable annotation, then returned array size will be 0 or 1. If specified type is repeatable annotation, then all the annotations of that type will be returned. Array size might be 0, 1 or more. It searches through superclasses until it finds the inherited specified annotationClass.- Specified by:
getAnnotationsByType
in interfaceAnnotatedElement
- Type Parameters:
A
- the type of the annotation to query for and return if present- Parameters:
annotationClass
- the annotation type to search for- Returns:
- array of declared annotations in the specified annotation type
- Since:
- 1.8
-
isAnnotation
public boolean isAnnotation()Answer if this class is an Annotation.- Returns:
- true if this class is an Annotation
- Since:
- 1.5
-
isAnnotationPresent
Answer if the specified Annotation exists for this Class. Inherited Annotations are searched.- Specified by:
isAnnotationPresent
in interfaceAnnotatedElement
- Parameters:
annotation
- the Annotation type- Returns:
- true if the specified Annotation exists
- Since:
- 1.5
-
asSubclass
Cast this Class to a subclass of the specified Class.- Type Parameters:
U
- the type for casting to- Parameters:
cls
- the Class to cast to- Returns:
- this Class, cast to a subclass of the specified Class
- Throws:
ClassCastException
- if this Class is not the same or a subclass of the specified Class- Since:
- 1.5
-
cast
Cast the specified object to this Class.- Parameters:
object
- the object to cast- Returns:
- the specified object, cast to this Class
- Throws:
ClassCastException
- if the specified object cannot be cast to this Class- Since:
- 1.5
-
isEnum
public boolean isEnum()Answer if this Class is an enum.- Returns:
- true if this Class is an enum
- Since:
- 1.5
-
getEnumConstants
Answer the array of enum constants for this Class. Returns null if this class is not an enum.- Returns:
- the array of enum constants, or null
- Since:
- 1.5
-
isSynthetic
public boolean isSynthetic()Answer if this Class is synthetic. A synthetic Class is created by the compiler.- Returns:
- true if this Class is synthetic.
- Since:
- 1.5
-
getTypeParameters
Answers an array of TypeVariable for the generic parameters declared on this Class.- Specified by:
getTypeParameters
in interfaceGenericDeclaration
- Returns:
- the TypeVariable[] for the generic parameters
- Since:
- 1.5
-
getGenericInterfaces
Answers an array of Type for the Class objects which match the interfaces specified in the receiver classesimplements
declaration.- Returns:
- Type[] the interfaces the receiver claims to implement.
- Since:
- 1.5
-
getGenericSuperclass
Answers the Type for the Class which represents the receiver's superclass. For classes which represent base types, interfaces, and for java.lang.Object the method answers null.- Returns:
- the Type for the receiver's superclass.
- Since:
- 1.5
-
getEnclosingConstructor
If this Class is defined inside a constructor, return the Constructor.- Returns:
- the enclosing Constructor or null
- Throws:
SecurityException
- if declared member access or package access is not allowed- Since:
- 1.5
- See Also:
-
getEnclosingMethod
If this Class is defined inside a method, return the Method.- Returns:
- the enclosing Method or null
- Throws:
SecurityException
- if declared member access or package access is not allowed- Since:
- 1.5
- See Also:
-
getEnclosingClass
Return the enclosing Class of this Class. Unlike getDeclaringClass(), this method works on any nested Class, not just classes nested directly in other classes.- Returns:
- the enclosing Class or null
- Throws:
SecurityException
- if package access is not allowed- Since:
- 1.5
- See Also:
-
getSimpleName
Return the simple name of this Class. The simple name does not include the package or the name of the enclosing class. The simple name of an anonymous class is "".- Returns:
- the simple name
- Since:
- 1.5
- See Also:
-
getCanonicalName
Return the canonical name of this Class. The canonical name is null for a local or anonymous class. The canonical name includes the package and the name of the enclosing class.- Returns:
- the canonical name or null
- Since:
- 1.5
- See Also:
-
isAnonymousClass
public boolean isAnonymousClass()Answer if this Class is anonymous. An unnamed Class defined inside a method.- Returns:
- true if this Class is anonymous.
- Since:
- 1.5
- See Also:
-
isLocalClass
public boolean isLocalClass()Answer if this Class is local. A named Class defined inside a method.- Returns:
- true if this Class is local.
- Since:
- 1.5
- See Also:
-
isMemberClass
public boolean isMemberClass()Answer if this Class is a member Class. A Class defined inside another Class.- Returns:
- true if this Class is local.
- Since:
- 1.5
- See Also:
-
getNestHost
Answers the host class of the receiver's nest.- Returns:
- the host class of the receiver.
- Throws:
SecurityException
- if nestHost is not same as the current class, a security manager is present, the classloader of the caller is not the same or an ancestor of nestHost class, and checkPackageAccess() denies access
-
isNestmateOf
Returns true if the class passed has the same nest top as this class.- Parameters:
that
- The class to compare- Returns:
- true if class is a nestmate of this class; false otherwise.
-
getNestMembers
Answers the nest member classes of the receiver's nest host.- Returns:
- the host class of the receiver.
- Throws:
SecurityException
- if a SecurityManager is present and package access is not allowedSecurityException
- if a returned class is not the current class, a security manager is enabled, the caller's class loader is not the same or an ancestor of that returned class, and the checkPackageAccess() denies access
-
arrayType
Create class of an array. The component type will be this Class instance.- Specified by:
arrayType
in interfaceTypeDescriptor.OfField<T>
- Returns:
- array class where the component type is this Class instance
-
componentType
Answers a Class object which represents the receiver's component type if the receiver represents an array type. The component type of an array type is the type of the elements of the array.- Specified by:
componentType
in interfaceTypeDescriptor.OfField<T>
- Returns:
- the component type of the receiver. Returns null if the receiver does not represent an array.
-
describeConstable
Returns the nominal descriptor of this Class instance, or an empty Optional if construction is not possible.- Specified by:
describeConstable
in interfaceConstable
- Returns:
- Optional with a nominal descriptor of Class instance
-
descriptorString
Return field descriptor of Class instance.- Specified by:
descriptorString
in interfaceTypeDescriptor
- Returns:
- field descriptor of Class instance
-
isRecord
public boolean isRecord()Returns true if the class instance is a record.- Returns:
- true for a record class, false otherwise
-
getRecordComponents
Returns an array of RecordComponent objects for a record class.- Returns:
- array of RecordComponent objects, one for each component in the record. For a class that is not a record, null is returned. For a record with no components an empty array is returned.
- Throws:
SecurityException
- if declared member access or package access is not allowed
-
isSealed
public boolean isSealed()Returns true if class or interface is sealed.- Returns:
- true if class is sealed, false otherwise
-
isHidden
public boolean isHidden()Returns true if the class is a hidden class.- Returns:
- true for a hidden class, false otherwise
-
getPermittedSubclasses
Returns the permitted subclasses related to the calling sealed class as an array of Class objects. If the calling class is not a sealed class, is an array class, or is primitive, then this method returns null instead. The order of any classes returned in the array is unspecified, and any classes that cannot be loaded are not included in the returned array. The returned array may be empty if there are no permitted subclasses.- Returns:
- array of Class objects if permitted subclasses exist or null if not a sealed class.
- Throws:
SecurityException
- if access to any of the classes returned in the array is denied- Since:
- 16
-