- All Superinterfaces:
ConstantDesc,TypeDescriptor,TypeDescriptor.OfField<ClassDesc>
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(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.
- Since:
- 12
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from 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 TypeMethodDescriptiondefault ClassDescdefault ClassDescarrayType(int rank) default ClassDescReturns the component type of this ClassDesc, if it describes an array type, ornullotherwise.Returns a field type descriptor string for this typedefault StringReturns a human-readable name for the type described by this descriptor.booleanCompare the specified object with this descriptor for equality.default booleanisArray()Returns whether this ClassDesc describes an array type.default booleanReturns whether this ClassDesc describes a class or interface type.default booleanReturns whether this ClassDesc describes a primitive type.default ClassDescdefault ClassDescstatic ClassDescReturns a ClassDesc for a class or interface type, given the name of the class or interface, such as"java.lang.String".static ClassDescReturns a ClassDesc for a class or interface type, given a package name and the unqualified (simple) name for the class or interface.static ClassDescofDescriptor(String descriptor) Returns a ClassDesc given a descriptor string for a class, interface, array, or primitive type.static ClassDescofInternalName(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".default StringReturns the package name of this ClassDesc, if it describes a class or interface type.Class<?> Resolves this descriptor reflectively, emulating the resolution behavior of JVMS and the access control behavior of JVMS .
-
Method Details
-
of
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 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:
- a ClassDesc describing the desired class
- Throws:
NullPointerException- if the argument isnullIllegalArgumentException- if the name string is not in the correct format- See Also:
-
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".- Parameters:
name- the fully qualified class name, in internal (slash-separated) form- Returns:
- a ClassDesc describing the desired class
- Throws:
NullPointerException- if the argument isnullIllegalArgumentException- if the name string is not in the correct format- Since:
- 20
- See Also:
-
of
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- 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 name- Returns:
- a ClassDesc describing the desired class
- Throws:
NullPointerException- if any argument isnullIllegalArgumentException- if the package name or class name are not in the correct format
-
ofDescriptor
Returns a ClassDesc given a descriptor string for a class, interface, array, or primitive type.- Parameters:
descriptor- a field descriptor string- Returns:
- a ClassDesc describing the desired class
- Throws:
NullPointerException- if the argument isnullIllegalArgumentException- if the descriptor string is not in the correct format- See Also:
-
arrayType
- Specified by:
arrayTypein interfaceTypeDescriptor.OfField<ClassDesc>- Returns:
- a ClassDesc describing the array type
- Throws:
IllegalStateException- if the resulting ClassDesc would have an array rank of greater than 255
-
arrayType
Returns a ClassDesc for an array type of the specified rank, whose component type is described by this ClassDesc.- Parameters:
rank- the rank of the array- Returns:
- a ClassDesc 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
-
nested
- Parameters:
nestedName- the unqualified name of the nested class- Returns:
- a ClassDesc describing the nested class
- Throws:
NullPointerException- if the argument isnullIllegalStateException- if this ClassDesc does not describe a class or interface typeIllegalArgumentException- if the nested class name is invalid
-
nested
- Parameters:
firstNestedName- the unqualified name of the first level of nested classmoreNestedNames- the unqualified name(s) of the remaining levels of nested class- Returns:
- a ClassDesc describing the nested class
- Throws:
NullPointerException- if any argument or its contents isnullIllegalStateException- if this ClassDesc does not describe a class or interface typeIllegalArgumentException- if the nested class name is invalid
-
isArray
default boolean isArray()Returns whether this ClassDesc describes an array type.- Specified by:
isArrayin interfaceTypeDescriptor.OfField<ClassDesc>- Returns:
- whether this ClassDesc describes an array type
-
isPrimitive
default boolean isPrimitive()Returns whether this ClassDesc describes a primitive type.- Specified by:
isPrimitivein interfaceTypeDescriptor.OfField<ClassDesc>- Returns:
- whether this ClassDesc describes a primitive type
-
isClassOrInterface
default boolean isClassOrInterface()Returns whether this ClassDesc describes a class or interface type.- Returns:
- whether this ClassDesc describes a class or interface type
-
componentType
Returns the component type of this ClassDesc, if it describes an array type, ornullotherwise.- Specified by:
componentTypein interfaceTypeDescriptor.OfField<ClassDesc>- Returns:
- a ClassDesc describing the component type, or
nullif this descriptor does not describe an array type
-
packageName
Returns the package name of this ClassDesc, 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 this ClassDesc does not describe a class or interface type
-
displayName
Returns a human-readable name for the type described by this descriptor.- Returns:
- the human-readable name
-
descriptorString
String descriptorString()Returns a field type descriptor string for this type- Specified by:
descriptorStringin interfaceTypeDescriptor- Returns:
- the descriptor string
-
resolveConstantDesc
Description copied from interface:ConstantDescResolves this descriptor reflectively, emulating the resolution behavior of JVMS and the access control behavior of JVMS . The resolution and access control context is provided by theMethodHandles.Lookupparameter. No caching of the resulting value is performed.- Specified by:
resolveConstantDescin interfaceConstantDesc- Parameters:
lookup- TheMethodHandles.Lookupto provide name resolution and access control context- Returns:
- the resolved constant value
- Throws:
ReflectiveOperationException- if a class, method, or field could not be reflectively resolved in the course of resolution
-
equals
Compare the specified object with this descriptor for equality. Returnstrueif and only if the specified object is also a ClassDesc and both describe the same type.
-