ConstantDesc
, TypeDescriptor
, TypeDescriptor.OfField<ClassDesc>
public sealed interface ClassDesc extends ConstantDesc, TypeDescriptor.OfField<ClassDesc>
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(java.lang.String)
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.
TypeDescriptor.OfField<F extends TypeDescriptor.OfField<F>>, TypeDescriptor.OfMethod<F extends TypeDescriptor.OfField<F>,M extends TypeDescriptor.OfMethod<F,M>>
Modifier and Type | Method | Description |
---|---|---|
default ClassDesc |
arrayType() |
|
default ClassDesc |
arrayType |
|
default ClassDesc |
componentType() |
Returns the component type of this ClassDesc, if it describes an array type, or null otherwise. |
String |
descriptorString() |
Returns a field type descriptor string for this type |
default String |
displayName() |
Returns a human-readable name for the type described by this descriptor. |
boolean |
equals |
Compare the specified object with this descriptor for equality. |
default boolean |
isArray() |
Returns whether this ClassDesc describes an array type. |
default boolean |
isClassOrInterface() |
Returns whether this ClassDesc describes a class or interface type. |
default boolean |
isPrimitive() |
Returns whether this ClassDesc describes a primitive type. |
default ClassDesc |
nested |
|
default ClassDesc |
nested |
|
static ClassDesc |
of |
Returns a ClassDesc for a class or interface type, given the name of the class or interface, such as "java.lang.String" . |
static ClassDesc |
of |
Returns a ClassDesc for a class or interface type, given a package name and the unqualified (simple) name for the class or interface. |
static ClassDesc |
ofDescriptor |
Returns a ClassDesc given a descriptor string for a class, interface, array, or primitive type. |
static ClassDesc |
ofInternalName |
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" . |
default String |
packageName() |
Returns the package name of this ClassDesc, if it describes a class or interface type. |
Class |
resolveConstantDesc |
static ClassDesc of(String name)
"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
).name
- the fully qualified (dot-separated) binary class nameNullPointerException
- if the argument is null
IllegalArgumentException
- if the name string is not in the correct formatstatic ClassDesc ofInternalName(String name)
"java/lang/String"
.ofDescriptor(String)
or arrayType()
; to create a descriptor for a primitive type, use ofDescriptor(String)
or use the predefined constants in ConstantDescs
.name
- the fully qualified class name, in internal (slash-separated) formNullPointerException
- if the argument is null
IllegalArgumentException
- if the name string is not in the correct formatstatic ClassDesc of(String packageName, String className)
packageName
- the package name (dot-separated); if the package name is the empty string, the class is considered to be in the unnamed packageclassName
- the unqualified (simple) class nameNullPointerException
- if any argument is null
IllegalArgumentException
- if the package name or class name are not in the correct formatstatic ClassDesc ofDescriptor(String descriptor)
"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.descriptor
- a field descriptor stringNullPointerException
- if the argument is null
IllegalArgumentException
- if the descriptor string is not in the correct formatdefault ClassDesc arrayType()
arrayType
in interface TypeDescriptor.OfField<ClassDesc>
IllegalStateException
- if the resulting ClassDesc would have an array rank of greater than 255default ClassDesc arrayType(int rank)
rank
- the rank of the arrayIllegalArgumentException
- if the rank is less than or equal to zero or if the rank of the resulting array type is greater than 255default ClassDesc nested(String nestedName)
d
describes the class java.util.Map
, a descriptor for the class java.util.Map.Entry
could be obtained by d.nested("Entry")
.nestedName
- the unqualified name of the nested classNullPointerException
- if the argument is null
IllegalStateException
- if this ClassDesc does not describe a class or interface typeIllegalArgumentException
- if the nested class name is invaliddefault ClassDesc nested(String firstNestedName, String... moreNestedNames)
firstNestedName
- the unqualified name of the first level of nested classmoreNestedNames
- the unqualified name(s) of the remaining levels of nested classNullPointerException
- if any argument or its contents is null
IllegalStateException
- if this ClassDesc does not describe a class or interface typeIllegalArgumentException
- if the nested class name is invaliddefault boolean isArray()
isArray
in interface TypeDescriptor.OfField<ClassDesc>
default boolean isPrimitive()
isPrimitive
in interface TypeDescriptor.OfField<ClassDesc>
default boolean isClassOrInterface()
default ClassDesc componentType()
null
otherwise.componentType
in interface TypeDescriptor.OfField<ClassDesc>
null
if this descriptor does not describe an array typedefault String packageName()
default String displayName()
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.
String descriptorString()
descriptorString
in interface TypeDescriptor
Class<?> resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException
ConstantDesc
MethodHandles.Lookup
parameter. No caching of the resulting value is performed.resolveConstantDesc
in interface ConstantDesc
lookup
- The MethodHandles.Lookup
to provide name resolution and access control contextReflectiveOperationException
- if a class, method, or field could not be reflectively resolved in the course of resolutionboolean equals(Object o)
true
if and only if the specified object is also a ClassDesc and both describe the same type.
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/constant/ClassDesc.html