APIdia Launch Partner
Top Description Methods
java.lang.constant

public sealed Interface ClassDesc

extends ConstantDesc, TypeDescriptor.OfField<ClassDesc>
permits PrimitiveClassDescImpl, ClassOrInterfaceDescImpl, ArrayClassDescImpl
Known Direct Implementers
jdk.internal.constant.ArrayClassDescImpl, jdk.internal.constant.ClassOrInterfaceDescImpl, jdk.internal.constant.PrimitiveClassDescImpl
Imports
java.lang.invoke.MethodHandles, .TypeDescriptor, jdk.internal.constant.ArrayClassDescImpl, .ConstantUtils, .PrimitiveClassDescImpl, .ClassOrInterfaceDescImpl

A nominal descriptor for a Class constant.

For common system types, including all the primitive types, there are predefined ClassDesc constants in ConstantDescs. (The java.lang.constant APIs consider void to be a primitive type.) To create a ClassDesc for a class or interface type, use of or ofDescriptor(String); to create a ClassDesc for an array type, use ofDescriptor(String), or first obtain a ClassDesc for the component type and then call the arrayType() or arrayType(int) methods.

Since
12
See Also
ConstantDescs

Method Summary

Modifier and TypeMethod and Description
public ClassDesc

Returns:

a ClassDesc describing the array type
arrayType
()

Redeclares java.lang.invoke.TypeDescriptor.OfField.arrayType.

Returns a ClassDesc for an array type whose component type is described by this ClassDesc.

public ClassDesc

Returns:

a ClassDesc describing the array type
arrayType
(int
the rank of the array
rank
)

Returns a ClassDesc for an array type of the specified rank, whose component type is described by this ClassDesc.

public default ClassDesc

Returns:

a ClassDesc describing the component type, or null if this descriptor does not describe an array type
componentType
()

Implements java.lang.invoke.TypeDescriptor.OfField.componentType.

Returns the component type of this ClassDesc, if it describes an array type, or null otherwise.

public String

Returns:

the descriptor string
descriptorString
()

Redeclares java.lang.invoke.TypeDescriptor.descriptorString.

Returns a field type descriptor string for this type

public String

Returns:

a human-readable name for this ClassDesc
displayName
()

Returns a human-readable name for this ClassDesc.

public boolean

Returns:

whether this descriptor is equal to the other object
equals
(Object
the other object
o
)

Compare the specified object with this descriptor for equality.

public default boolean

Returns:

whether this ClassDesc describes an array type
isArray
()

Implements java.lang.invoke.TypeDescriptor.OfField.isArray.

Returns whether this ClassDesc describes an array type.

public default boolean

Returns:

whether this ClassDesc describes a class or interface type
isClassOrInterface
()

Returns whether this ClassDesc describes a class or interface type.

public default boolean

Returns:

whether this ClassDesc describes a primitive type
isPrimitive
()

Implements java.lang.invoke.TypeDescriptor.OfField.isPrimitive.

Returns whether this ClassDesc describes a primitive type.

public default ClassDesc

Returns:

a ClassDesc describing the nested class
nested
(String
the unqualified name of the nested class
nestedName
)

Returns a ClassDesc for a nested class of the class or interface type described by this ClassDesc.

public default ClassDesc

Returns:

a ClassDesc describing the nested class
nested
(String
the unqualified name of the first level of nested class
firstNestedName
,
String...
the unqualified name(s) of the remaining levels of nested class
moreNestedNames
)

Returns a ClassDesc for a nested class of the class or interface type described by this ClassDesc.

public static ClassDesc

Returns:

a ClassDesc describing the desired class
of
(String
the fully qualified (dot-separated) binary class name
name
)

Returns a ClassDesc for a class or interface type, given the name of the class or interface, such as "java.lang.String".

public static ClassDesc

Returns:

a ClassDesc describing the desired class
of
(String
the package name (dot-separated); if the package name is the empty string, the class is considered to be in the unnamed package
packageName
,
String
the unqualified (simple) class name
className
)

Returns a ClassDesc for a class or interface type, given a package name and the unqualified (simple) name for the class or interface.

public static ClassDesc

Returns:

a ClassDesc describing the desired class
ofDescriptor
(String
a field descriptor string
descriptor
)

Returns a ClassDesc given a descriptor string for a class, interface, array, or primitive type.

public static ClassDesc

Returns:

a ClassDesc describing the desired class
ofInternalName
(String
the fully qualified class name, in internal (slash-separated) form
name
)

Returns a ClassDesc for a class or interface type, given the name of the class or interface in internal form, such as "java/lang/String".

public default String

Returns:

the package name, or the empty string if the class is in the default package, or this ClassDesc does not describe a class or interface type
packageName
()

Returns the package name of this ClassDesc, if it describes a class or interface type.

public Class<?>
resolveConstantDesc(MethodHandles.Lookup lookup)

Redeclares java.lang.constant.ConstantDesc.resolveConstantDesc.

Resolves this descriptor reflectively, emulating the resolution behavior of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4.

Method Detail

arrayTypeback to summary
public ClassDesc arrayType()

Redeclares java.lang.invoke.TypeDescriptor.OfField.arrayType.

Returns a ClassDesc for an array type whose component type is described by this ClassDesc.

Returns:ClassDesc

a ClassDesc describing the array type

Exceptions
IllegalStateException:
if the resulting ClassDesc would have an array rank of greater than 255
Java Virtual Machine Specification
4.4.1 The CONSTANT_Class_info Structure
arrayTypeback to summary
public ClassDesc arrayType(int rank)

Returns a ClassDesc for an array type of the specified rank, whose component type is described by this ClassDesc.

Parameters
rank:int

the rank of the array

Returns:ClassDesc

a ClassDesc describing the array type

Exceptions
IllegalArgumentException:
if the rank is less than or equal to zero or if the rank of the resulting array type is greater than 255
Java Virtual Machine Specification
4.4.1 The CONSTANT_Class_info Structure
componentTypeback to summary
public default ClassDesc componentType()

Implements java.lang.invoke.TypeDescriptor.OfField.componentType.

Returns the component type of this ClassDesc, if it describes an array type, or null otherwise.

Returns:ClassDesc

a ClassDesc describing the component type, or null if this descriptor does not describe an array type

descriptorStringback to summary
public String descriptorString()

Redeclares java.lang.invoke.TypeDescriptor.descriptorString.

Returns a field type descriptor string for this type

Returns:String

the descriptor string

Java Virtual Machine Specification
4.3.2 Field Descriptors
displayNameback to summary
public String displayName()

Returns a human-readable name for this ClassDesc. For primitive types, this method returns the simple name (such as int). For class or interface types, this method returns the unqualified class name. For array types, this method returns the human-readable name of the component type suffixed with the appropriate number of [] pairs.

Returns:String

a human-readable name for this ClassDesc

equalsback to summary
public boolean equals(Object o)

Compare the specified object with this descriptor for equality. Returns true if and only if the specified object is also a ClassDesc and both describe the same type.

Parameters
o:Object

the other object

Returns:boolean

whether this descriptor is equal to the other object

isArrayback to summary
public default boolean isArray()

Implements java.lang.invoke.TypeDescriptor.OfField.isArray.

Returns whether this ClassDesc describes an array type.

Returns:boolean

whether this ClassDesc describes an array type

isClassOrInterfaceback to summary
public default boolean isClassOrInterface()

Returns whether this ClassDesc describes a class or interface type.

Returns:boolean

whether this ClassDesc describes a class or interface type

isPrimitiveback to summary
public default boolean isPrimitive()

Implements java.lang.invoke.TypeDescriptor.OfField.isPrimitive.

Returns whether this ClassDesc describes a primitive type.

Returns:boolean

whether this ClassDesc describes a primitive type

nestedback to summary
public default ClassDesc nested(String nestedName)

Returns a ClassDesc for a nested class of the class or interface type described by this ClassDesc.

API Note

Example: If descriptor d describes the class java.util.Map, a descriptor for the class java.util.Map.Entry could be obtained by d.nested("Entry").

Parameters
nestedName:String

the unqualified name of the nested class

Returns:ClassDesc

a ClassDesc describing the nested class

Exceptions
NullPointerException:
if the argument is null
IllegalStateException:
if this ClassDesc does not describe a class or interface type
IllegalArgumentException:
if the nested class name is invalid
nestedback to summary
public default ClassDesc nested(String firstNestedName, String... moreNestedNames)

Returns a ClassDesc for a nested class of the class or interface type described by this ClassDesc.

Parameters
firstNestedName:String

the unqualified name of the first level of nested class

moreNestedNames:String[]

the unqualified name(s) of the remaining levels of nested class

Returns:ClassDesc

a ClassDesc describing the nested class

Exceptions
NullPointerException:
if any argument or its contents is null
IllegalStateException:
if this ClassDesc does not describe a class or interface type
IllegalArgumentException:
if the nested class name is invalid
ofback to summary
public static ClassDesc of(String name)

Returns a ClassDesc 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 use ofDescriptor(String) or arrayType(); to create a descriptor for a primitive type, use ofDescriptor(String) or use the predefined constants in ConstantDescs).

Parameters
name:String

the fully qualified (dot-separated) binary class name

Returns:ClassDesc

a ClassDesc describing the desired class

Exceptions
NullPointerException:
if the argument is null
IllegalArgumentException:
if the name string is not in the correct format
See Also
ClassDesc#ofDescriptor(String), ClassDesc#ofInternalName(String)
ofback to summary
public static ClassDesc of(String packageName, String className)

Returns a ClassDesc for a class or interface type, given a package name and the unqualified (simple) name for the class or interface.

Parameters
packageName:String

the package name (dot-separated); if the package name is the empty string, the class is considered to be in the unnamed package

className:String

the unqualified (simple) class name

Returns:ClassDesc

a ClassDesc describing the desired class

Exceptions
NullPointerException:
if any argument is null
IllegalArgumentException:
if the package name or class name are not in the correct format
ofDescriptorback to summary
public static ClassDesc ofDescriptor(String descriptor)

Returns a ClassDesc 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:String

a field descriptor string

Returns:ClassDesc

a ClassDesc describing the desired class

Exceptions
NullPointerException:
if the argument is null
IllegalArgumentException:
if the descriptor string is not in the correct format
Java Virtual Machine Specification
4.3.2 Field Descriptors, 4.4.1 The CONSTANT_Class_info Structure
See Also
ClassDesc#of(String), ClassDesc#ofInternalName(String)
ofInternalNameback to summary
public static ClassDesc ofInternalName(String name)

Returns a ClassDesc for a class or interface type, given the name of the class or interface in internal form, such as "java/lang/String".

API Note

To create a descriptor for an array type, either use ofDescriptor(String) or arrayType(); to create a descriptor for a primitive type, use ofDescriptor(String) or use the predefined constants in ConstantDescs.

Parameters
name:String

the fully qualified class name, in internal (slash-separated) form

Returns:ClassDesc

a ClassDesc describing the desired class

Exceptions
NullPointerException:
if the argument is null
IllegalArgumentException:
if the name string is not in the correct format
Since
20
Java Virtual Machine Specification
4.2.1 Binary Class and Interface Names
See Also
ClassDesc#of(String), ClassDesc#ofDescriptor(String)
packageNameback to summary
public default String packageName()

Returns the package name of this ClassDesc, if it describes a class or interface type.

Returns:String

the package name, or the empty string if the class is in the default package, or this ClassDesc does not describe a class or interface type

resolveConstantDescback to summary
public Class<?> resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException

Redeclares java.lang.constant.ConstantDesc.resolveConstantDesc.

Doc from java.lang.constant.ConstantDesc.resolveConstantDesc.

Resolves this descriptor reflectively, emulating the resolution behavior of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4. The resolution and access control context is provided by the MethodHandles.Lookup parameter. No caching of the resulting value is performed.

Annotations
@Override
Exceptions
ReflectiveOperationException:
if a class, method, or field could not be reflectively resolved in the course of resolution
Since
21