Module java.base
Package java.lang.constant

Interface ClassDesc

All Superinterfaces:
ConstantDesc,TypeDescriptor,TypeDescriptor.OfField<ClassDesc>

public sealed interfaceClassDescextendsConstantDesc,TypeDescriptor.OfField<ClassDesc>
Anominal descriptor for aClass constant.

For common system types, including all the primitive types, there are predefinedClassDesc constants inConstantDescs. (Thejava.lang.constant APIs considervoid to be a primitive type.) To create aClassDesc for a class or interface type, useof(java.lang.String) orofDescriptor(String); to create aClassDesc for an array type, useofDescriptor(String), or first obtain aClassDesc for the component type and then call thearrayType() orarrayType(int) methods.

Since:
12
See Also:
  • Method Details

    • of

      static ClassDesc of(String name)
      Returns aClassDesc for a class or interface type, given the name of the class or interface, such as"java.lang.String". (To create a descriptor for an array type, either useofDescriptor(String) orarrayType(); to create a descriptor for a primitive type, useofDescriptor(String) or use the predefined constants inConstantDescs).
      Parameters:
      name - the fully qualified (dot-separated) binary class name
      Returns:
      aClassDesc describing the desired class
      Throws:
      NullPointerException - if the argument isnull
      IllegalArgumentException - if the name string is not in the correct format
    • of

      static ClassDesc of(String packageName,String className)
      Returns aClassDesc for a class or interface type, given a package name and the unqualified (simple) name for the class or interface.
      Parameters:
      packageName - the package name (dot-separated); if the package name is the empty string, the class is considered to be in the unnamed package
      className - the unqualified (simple) class name
      Returns:
      aClassDesc describing the desired class
      Throws:
      NullPointerException - if any argument isnull
      IllegalArgumentException - if the package name or class name are not in the correct format
    • ofDescriptor

      static ClassDesc ofDescriptor(String descriptor)
      Returns aClassDesc given a descriptor string for a class, interface, array, or primitive type.
      API Note:
      A field type descriptor string for a non-array type is either a one-letter code corresponding to a primitive type ("J", "I", "C", "S", "B", "D", "F", "Z", "V"), or the letter"L", followed by the fully qualified binary name of a class, followed by";". A field type descriptor for an array type is the character"[" followed by the field descriptor for the component type. Examples of valid type descriptor strings include"Ljava/lang/String;","I","[I","V","[Ljava/lang/String;", etc. See JVMS 4.3.2 ("Field Descriptors") for more detail.
      Parameters:
      descriptor - a field descriptor string
      Returns:
      aClassDesc describing the desired class
      Throws:
      NullPointerException - if the argument isnull
      IllegalArgumentException - if the name string is not in the correct format
      SeeJava Virtual Machine Specification:
      4.3.2 Field Descriptors
      4.4.1 The CONSTANT_Class_info Structure
    • arrayType

      default ClassDesc arrayType()
      Returns aClassDesc for an array type whose component type is described by thisClassDesc.
      Specified by:
      arrayType in interface TypeDescriptor.OfField<ClassDesc>
      Returns:
      aClassDesc describing the array type
      Throws:
      IllegalStateException - if the resultingClassDesc would have an array rank of greater than 255
      SeeJava Virtual Machine Specification:
      4.4.1 The CONSTANT_Class_info Structure
    • arrayType

      default ClassDesc arrayType(int rank)
      Returns aClassDesc for an array type of the specified rank, whose component type is described by thisClassDesc.
      Parameters:
      rank - the rank of the array
      Returns:
      aClassDesc describing the array type
      Throws:
      IllegalArgumentException - if the rank is less than or equal to zero or if the rank of the resulting array type is greater than 255
      SeeJava Virtual Machine Specification:
      4.4.1 The CONSTANT_Class_info Structure
    • nested

      default ClassDesc nested(String nestedName)
      Returns aClassDesc for a nested class of the class or interface type described by thisClassDesc.
      API Note:
      Example: If descriptord describes the classjava.util.Map, a descriptor for the classjava.util.Map.Entry could be obtained byd.nested("Entry").
      Parameters:
      nestedName - the unqualified name of the nested class
      Returns:
      aClassDesc describing the nested class
      Throws:
      NullPointerException - if the argument isnull
      IllegalStateException - if thisClassDesc does not describe a class or interface type
      IllegalArgumentException - if the nested class name is invalid
    • nested

      default ClassDesc nested(String firstNestedName,String... moreNestedNames)
      Returns aClassDesc for a nested class of the class or interface type described by thisClassDesc.
      Parameters:
      firstNestedName - the unqualified name of the first level of nested class
      moreNestedNames - the unqualified name(s) of the remaining levels of nested class
      Returns:
      aClassDesc describing the nested class
      Throws:
      NullPointerException - if any argument or its contents isnull
      IllegalStateException - if thisClassDesc does not describe a class or interface type
      IllegalArgumentException - if the nested class name is invalid
    • isArray

      default boolean isArray()
      Returns whether thisClassDesc describes an array type.
      Specified by:
      isArray in interface TypeDescriptor.OfField<ClassDesc>
      Returns:
      whether thisClassDesc describes an array type
    • isPrimitive

      default boolean isPrimitive()
      Returns whether thisClassDesc describes a primitive type.
      Specified by:
      isPrimitive in interface TypeDescriptor.OfField<ClassDesc>
      Returns:
      whether thisClassDesc describes a primitive type
    • isClassOrInterface

      default boolean isClassOrInterface()
      Returns whether thisClassDesc describes a class or interface type.
      Returns:
      whether thisClassDesc describes a class or interface type
    • componentType

      default ClassDesc componentType()
      Returns the component type of thisClassDesc, if it describes an array type, ornull otherwise.
      Specified by:
      componentType in interface TypeDescriptor.OfField<ClassDesc>
      Returns:
      aClassDesc describing the component type, ornull if this descriptor does not describe an array type
    • packageName

      default String packageName()
      Returns the package name of thisClassDesc, if it describes a class or interface type.
      Returns:
      the package name, or the empty string if the class is in the default package, or thisClassDesc does not describe a class or interface type
    • displayName

      default String displayName()
      Returns a human-readable name for the type described by this descriptor.
      Implementation Requirements:

      The default implementation returns the simple name (e.g.,int) for primitive types, the unqualified class name for class or interface types, or the display name of the component type suffixed with the appropriate number of[] pairs for array types.

      Returns:
      the human-readable name
    • descriptorString

      String descriptorString()
      Returns a field type descriptor string for this type
      Specified by:
      descriptorString in interface TypeDescriptor
      Returns:
      the descriptor string
      SeeJava Virtual Machine Specification:
      4.3.2 Field Descriptors
    • equals

      boolean equals(Object o)
      Compare the specified object with this descriptor for equality. Returnstrue if and only if the specified object is also aClassDesc and both describe the same type.
      Overrides:
      equals in class Object
      Parameters:
      o - the other object
      Returns:
      whether this descriptor is equal to the other object
      See Also: