ConstantDesc
, TypeDescriptor
, TypeDescriptor.OfField<ClassDesc>
public 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.
Two ClassDesc objects are considered Object.equals(Object)
if they describe exactly the same type.
ConstantDescs
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(int rank) |
|
default ClassDesc |
componentType() |
Returns the component type of this ClassDesc, if it describes
an array type, or
null otherwise. |
String |
descriptorString() |
Return a field type descriptor string for this type
|
default String |
displayName() |
Returns a human-readable name for the type described by this descriptor.
|
default ClassDesc |
inner(String innerName) |
|
default ClassDesc |
inner(String firstInnerName,
String... moreInnerNames) |
|
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.
|
static ClassDesc |
of(String name) |
Create a ClassDesc for a class or interface type,
given the name of the class or interface, such as
"java.lang.String" . |
static ClassDesc |
of(String packageName,
String className) |
Create 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(String descriptor) |
Create a ClassDesc given a descriptor string for a class,
interface, array, or primitive type.
|
default String |
packageName() |
Returns the package name of this ClassDesc, if it describes
a class or interface type.
|
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 any 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)
descriptor
- a field descriptor stringNullPointerException
- if any argument is null
IllegalArgumentException
- if the name string is not in the
correct formatdefault ClassDesc arrayType()
arrayType
in interface TypeDescriptor.OfField<ClassDesc>
default ClassDesc arrayType(int rank)
rank
- the rank of the arrayIllegalArgumentException
- if the rank is zero or negativedefault ClassDesc inner(String innerName)
innerName
- the unqualified name of the inner classNullPointerException
- if any argument is null
IllegalStateException
- if this ClassDesc does not
describe a class or interface typedefault ClassDesc inner(String firstInnerName, String... moreInnerNames)
firstInnerName
- the unqualified name of the first level of inner classmoreInnerNames
- the unqualified name(s) of the remaining levels of
inner classNullPointerException
- if any argument is null
IllegalStateException
- if this ClassDesc does not
describe a class or interface typedefault 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()
String descriptorString()
descriptorString
in interface TypeDescriptor