Module java.base
Package java.lang

Class Class<T>

java.lang.Object
java.lang.Class<T>
All Implemented Interfaces:
Serializable, Constable, TypeDescriptor, TypeDescriptor.OfField<Class<?>>, AnnotatedElement, GenericDeclaration, Type

public final class Class<T> extends Object implements Serializable, GenericDeclaration, Type, Constable, TypeDescriptor, TypeDescriptor.OfField<Class<?>>
An instance of class Class is the in-image representation of a Java class. There are three basic types of Classes
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 the byte base type
  • S representing the short base type
  • I representing the int base type
  • J representing the long base type
  • F representing the float base type
  • D representing the double base type
  • C representing the char base type
  • Z representing the boolean base type
  • V representing void function return values
The name of a Class representing a base type is the keyword which is used to represent the type in Java source code (i.e. "int" for the 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:
  • Method Details

    • forName

      public static Class<?> forName(String className) 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.
      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 find
      initializeBoolean - A boolean indicating whether the class should be initialized
      classLoader - The classloader to use to load the class
      Returns:
      the named class.
      Throws:
      ClassNotFoundException - If the class could not be found
      See Also:
    • forName

      public static Class<?> forName(Module module, String name)
      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 module
      name - The name of the non-base type class to find
      Returns:
      The Class object representing the named class
      See Also:
    • getClasses

      public Class<?>[] getClasses() throws SecurityException
      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

      public ClassLoader 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

      public Class<?> 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

      public Constructor<?>[] getConstructors() throws SecurityException
      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

      public Class<?>[] getDeclaredClasses() throws SecurityException
      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

      public Constructor<?>[] getDeclaredConstructors() throws SecurityException
      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

      public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException
      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 found
      SecurityException - if member access is not allowed
      See Also:
    • getDeclaredFields

      public Field[] getDeclaredFields() throws SecurityException
      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 method
      parameterTypes - 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

      public Method[] getDeclaredMethods() throws SecurityException
      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

      public Class<?> getDeclaringClass() throws SecurityException
      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.
      Throws:
      SecurityException - if member access is not allowed
    • getField

      public Field getField(String name) throws NoSuchFieldException, SecurityException
      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 exist
      SecurityException - If access is denied
      See Also:
    • getFields

      public Field[] getFields() throws SecurityException
      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

      public Class<?>[] getInterfaces()
      Answers an array of Class objects which match the interfaces specified in the receiver classes implements 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 method
      parameterTypes - 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

      public Method[] getMethods() throws SecurityException
      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

      public Module 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

      public String 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

      public ProtectionDomain getProtectionDomain() throws SecurityException
      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.
      Throws:
      SecurityException - if the RuntimePermission "getProtectionDomain" is not allowed
      See Also:
    • getPackageName

      public String 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

      public URL getResource(String resName)
      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

      public InputStream getResourceAsStream(String resName)
      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

      public Object[] 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

      public Class<? super T> 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 interface TypeDescriptor.OfField<T>
      Returns:
      true if the receiver represents an array class false if it does not represent an array class
    • isAssignableFrom

      public 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).
      Parameters:
      cls - Class the class to test
      Returns:
      true the argument can be assigned into the receiver false the argument cannot be assigned into the receiver
      Throws:
      NullPointerException - if the parameter is null
    • isInstance

      public boolean isInstance(Object object)
      Answers true if the argument is non-null and can be cast to the type of the receiver. This is the runtime version of the instanceof operator.
      Parameters:
      object - Object the object to test
      Returns:
      true the argument can be cast to the type of the receiver false 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 interface false if it does not represent an interface
    • isPrimitive

      public boolean isPrimitive()
      Answers true if the receiver represents a base type.
      Specified by:
      isPrimitive in interface TypeDescriptor.OfField<T>
      Returns:
      true if the receiver represents a base type false if it does not represent a base type
    • newInstance

      @Deprecated(forRemoval=false, since="9") public T newInstance() throws IllegalAccessException, InstantiationException
      Deprecated.
      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

      public String toString()
      Answers a string containing a concise, human-readable description of the receiver.
      Overrides:
      toString in class Object
      Returns:
      a printable representation for the receiver.
    • toGenericString

      public String toGenericString()
      Returns a formatted string describing this Class. The string has the following format: modifier1 modifier2 ... kind name<typeparam1, typeparam2, ...>. kind is one of class, 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

      public Package 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

      public <A extends Annotation> A getAnnotation(Class<A> annotation)
      Return the specified Annotation for this Class. Inherited Annotations are searched.
      Specified by:
      getAnnotation in interface AnnotatedElement
      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

      public Annotation[] 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 interface AnnotatedElement
      Returns:
      an array of Annotation
      Since:
      1.5
    • getDeclaredAnnotation

      public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotation)
      Looks through directly declared annotations for this class, not including Annotations inherited from superclasses.
      Specified by:
      getDeclaredAnnotation in interface AnnotatedElement
      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

      public AnnotatedType[] getAnnotatedInterfaces()
      Return the annotated types for the implemented interfaces.
      Returns:
      array, possibly empty, of AnnotatedTypes
    • getAnnotatedSuperclass

      public AnnotatedType 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

      public String getTypeName()
      Answers the type name of the class which the receiver represents.
      Specified by:
      getTypeName in interface Type
      Returns:
      the fully qualified type name, with brackets if an array class
      Since:
      1.8
    • getDeclaredAnnotations

      public Annotation[] 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 interface AnnotatedElement
      Returns:
      an array of declared annotations
      Since:
      1.5
    • getDeclaredAnnotationsByType

      public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationClass)
      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
      
                      @interface ContainerAnnotation {RepeatableAnn[] value();}
                      @Repeatable(ContainerAnnotation.class)
                      
      Container Annotation:

      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 interface AnnotatedElement
      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

      public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass)
      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 interface AnnotatedElement
      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

      public boolean isAnnotationPresent(Class<? extends Annotation> annotation)
      Answer if the specified Annotation exists for this Class. Inherited Annotations are searched.
      Specified by:
      isAnnotationPresent in interface AnnotatedElement
      Parameters:
      annotation - the Annotation type
      Returns:
      true if the specified Annotation exists
      Since:
      1.5
    • asSubclass

      public <U> Class<? extends U> asSubclass(Class<U> cls)
      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

      public T cast(Object object)
      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

      public T[] 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

      public TypeVariable<Class<T>>[] getTypeParameters()
      Answers an array of TypeVariable for the generic parameters declared on this Class.
      Specified by:
      getTypeParameters in interface GenericDeclaration
      Returns:
      the TypeVariable[] for the generic parameters
      Since:
      1.5
    • getGenericInterfaces

      public Type[] getGenericInterfaces()
      Answers an array of Type for the Class objects which match the interfaces specified in the receiver classes implements declaration.
      Returns:
      Type[] the interfaces the receiver claims to implement.
      Since:
      1.5
    • getGenericSuperclass

      public Type 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

      public Constructor<?> getEnclosingConstructor() throws SecurityException
      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

      public Method getEnclosingMethod() throws SecurityException
      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

      public Class<?> getEnclosingClass() throws SecurityException
      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

      public String 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

      public String 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

      public Class<?> getNestHost() throws SecurityException
      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

      public boolean isNestmateOf(Class<?> that)
      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

      public Class<?>[] getNestMembers() throws SecurityException
      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 allowed
      SecurityException - 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

      public Class<?> arrayType()
      Create class of an array. The component type will be this Class instance.
      Specified by:
      arrayType in interface TypeDescriptor.OfField<T>
      Returns:
      array class where the component type is this Class instance
    • componentType

      public Class<?> 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 interface TypeDescriptor.OfField<T>
      Returns:
      the component type of the receiver. Returns null if the receiver does not represent an array.
    • describeConstable

      public Optional<ClassDesc> describeConstable()
      Returns the nominal descriptor of this Class instance, or an empty Optional if construction is not possible.
      Specified by:
      describeConstable in interface Constable
      Returns:
      Optional with a nominal descriptor of Class instance
    • descriptorString

      public String descriptorString()
      Return field descriptor of Class instance.
      Specified by:
      descriptorString in interface TypeDescriptor
      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

      public RecordComponent[] getRecordComponents() throws SecurityException
      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

      public Class<?>[] getPermittedSubclasses() throws SecurityException
      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