Interface ClassDesc
- All Superinterfaces:
ConstantDesc,TypeDescriptor,TypeDescriptor.OfField<ClassDesc>
Anominal descriptor for a
Class constant.For common system types, including all the primitive types, there arepredefinedClassDesc constants inConstantDescs.(Thejava.lang.constant APIs considervoid to be a primitive type.)To create aClassDesc for a class or interface type, useof(String) orofDescriptor(String); to create aClassDesc for an arraytype, useofDescriptor(String), or first obtain aClassDesc for the component type and then call thearrayType()orarrayType(int) methods.
- Since:
- 12
- See Also:
Nested Class Summary
Nested classes/interfaces declared in interface TypeDescriptor
TypeDescriptor.OfField<F>,TypeDescriptor.OfMethod<F,M> Method Summary
Modifier and TypeMethodDescriptionarrayType(int rank) defaultClassDescReturns the component type of thisClassDesc, if it describesan array type, ornullotherwise.Returns a field type descriptor string for this typeReturns a human-readable name for thisClassDesc.booleanCompare the specified object with this descriptor for equality.default booleanisArray()Returns whether thisClassDesc describes an array type.default booleanReturns whether thisClassDesc describes a class or interface type.default booleanReturns whether thisClassDesc describes a primitive type.defaultClassDescdefaultClassDescstaticClassDescReturns aClassDesc for a class or interface type,given the name of the class or interface, such as"java.lang.String".staticClassDescReturns aClassDesc for a class or interface type,given a package name and the unqualified (simple) name for theclass or interface.staticClassDescofDescriptor(String descriptor) Returns aClassDesc given a descriptor string for a class,interface, array, or primitive type.staticClassDescofInternalName(String name) Returns aClassDesc for a class or interface type,given the name of the class or interface in internal form,such as"java/lang/String".defaultStringReturns the package name of thisClassDesc, if it describesa class or interface type.Class<?>
Method Details
of
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 isnullIllegalArgumentException- if the name string is not in thecorrect format- See Also:
ofInternalName
Returns aClassDesc 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)orarrayType(); to create a descriptor for a primitive type, useofDescriptor(String)or use the predefined constants inConstantDescs. - Parameters:
name- the fully qualified class name, in internal (slash-separated) form- Returns:
- aClassDesc describing the desired class
- Throws:
NullPointerException- if the argument isnullIllegalArgumentException- if the name string is not in thecorrect format- SeeJava Virtual Machine Specification:
- 4.2.1 Binary Class and Interface Names
- Since:
- 20
- See Also:
of
Returns aClassDesc for a class or interface type,given a package name and the unqualified (simple) name for theclass 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:
- aClassDesc describing the desired class
- Throws:
NullPointerException- if any argument isnullIllegalArgumentException- if the package name or class name arenot in the correct format
ofDescriptor
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 eithera one-letter code corresponding to a primitive type(
"J", "I", "C", "S", "B", "D", "F", "Z", "V"), or the letter"L", followedby 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 ofvalid type descriptor strings include"Ljava/lang/String;","I","[I","V","[Ljava/lang/String;", etc.See JVMS4.3.2("Field Descriptors") for more detail. - Parameters:
descriptor- a field descriptor string- Returns:
- aClassDesc describing the desired class
- Throws:
NullPointerException- if the argument isnullIllegalArgumentException- if the descriptor string is not in thecorrect format- SeeJava Virtual Machine Specification:
- 4.3.2 Field Descriptors
4.4.1 The CONSTANT_Class_info Structure - See Also:
arrayType
ClassDesc arrayType()- Specified by:
arrayTypein interfaceTypeDescriptor.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
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 orequal to zero or if the rank of the resulting array type isgreater than 255- SeeJava Virtual Machine Specification:
- 4.4.1 The CONSTANT_Class_info Structure
nested
- API Note:
- Example: If descriptor
ddescribes the classjava.util.Map, adescriptor for the classjava.util.Map.Entrycould be obtainedbyd.nested("Entry"). - Parameters:
nestedName- the unqualified name of the nested class- Returns:
- aClassDesc describing the nested class
- Throws:
NullPointerException- if the argument isnullIllegalStateException- if thisClassDesc does notdescribe 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:
- aClassDesc describing the nested class
- Throws:
NullPointerException- if any argument or its contents isnullIllegalStateException- if thisClassDesc does notdescribe a class or interface typeIllegalArgumentException- if the nested class name is invalid
isArray
default boolean isArray()Returns whether thisClassDesc describes an array type.- Specified by:
isArrayin interfaceTypeDescriptor.OfField<ClassDesc>- Returns:
- whether thisClassDesc describes an array type
isPrimitive
default boolean isPrimitive()Returns whether thisClassDesc describes a primitive type.- Specified by:
isPrimitivein interfaceTypeDescriptor.OfField<ClassDesc>- Returns:
- whether thisClassDesc describes a primitive type
isClassOrInterface
componentType
Returns the component type of thisClassDesc, if it describesan array type, ornullotherwise.- Specified by:
componentTypein interfaceTypeDescriptor.OfField<ClassDesc>- Returns:
- aClassDesc describing the component type, or
nullif this descriptor does not describe an array type
packageName
displayName
String displayName()Returns a human-readable name for thisClassDesc.For primitive types, this method returns the simple name (such asint).For class or interface types, this method returns the unqualified class name.For array types, this method returns the human-readable name of the componenttype suffixed with the appropriate number of[]pairs.- Returns:
- a human-readable name for this
ClassDesc
descriptorString
String descriptorString()Returns a field type descriptor string for this type- Specified by:
descriptorStringin interfaceTypeDescriptor- Returns:
- the descriptor string
- SeeJava Virtual Machine Specification:
- 4.3.2 Field Descriptors
resolveConstantDesc
Description copied from interface:ConstantDescResolves this descriptor reflectively, emulating the resolution behaviorof JVMS5.4.3 and the access control behavior of JVMS5.4.4. The resolutionand 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 fieldcould not be reflectively resolved in the course of resolution- Since:
- 21
equals