public class ArrayType extends ReferenceType
ArrayType: PrimitiveType [ ] { [ ] } ClassOrInterfaceType [ ] { [ ] } TypeVariable [ ] { [ ] }The type preceding the rightmost set of brackets is the component type, while the type preceding the brackets is the element type. An array may have components of any type.
Modifier and Type | Field and Description |
---|---|
private Type |
componentType
The type of components in this array.
|
private java.lang.Class<?> |
runtimeClass
The runtime type for this array.
|
Modifier | Constructor and Description |
---|---|
private |
ArrayType(Type componentType,
java.lang.Class<?> runtimeClass)
Creates an
ArrayType with the given component type and runtime class. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(@Nullable java.lang.Object obj) |
static ArrayType |
forClass(java.lang.Class<?> arrayClass)
Creates an array type for the given
java.lang.reflect.Class object. |
static ArrayType |
forType(java.lang.reflect.Type type)
Creates an
ArrayType from a java.lang.reflect.Type reference. |
java.lang.String |
getBinaryName()
Returns the binary name of this type, including type arguments if this is a parameterized type
(so, it isn't really a binary name).
|
Type |
getComponentType()
Returns the component type of this array type.
|
int |
getDimensions() |
Type |
getElementType()
Returns the element type of this array type.
|
java.lang.String |
getFqName()
Returns the fully-qualified name of this type, including type arguments if this is a
parameterized type.
|
Type |
getRawtype()
Returns the raw type for this type, which is this type except for generic types.
|
ArrayType |
getRawTypeArray()
Returns the non-parameterized form for this array type.
|
java.lang.Class<?> |
getRuntimeClass()
Returns the runtime
Class object for this type. |
java.lang.String |
getSimpleName()
Returns the name of this type without type arguments or package qualifiers.
|
java.util.List<TypeVariable> |
getTypeParameters()
Returns the list of type parameters for this type.
|
boolean |
hasCaptureVariable()
Indicates whether this
ReferenceType has a capture variable. |
int |
hashCode() |
boolean |
hasParameterizedElementType()
Indicates whether this array type has a parameterized element type.
|
boolean |
hasWildcard()
Indicates whether this type has a wildcard anywhere within it.
|
boolean |
isArray()
Indicates whether this object represents an array type.
|
boolean |
isAssignableFrom(Type otherType)
Indicates whether there is an assignment conversion from a source
Type to this type. |
boolean |
isGeneric(boolean ignoreWildcards)
Indicate whether this type is generic.
|
boolean |
isSubtypeOf(Type otherType)
Test whether this type is a subtype of the given type according to transitive closure of
definition of the direct supertype relation in section 4.10 of
JLS for Java SE 8.
|
static ArrayType |
ofComponentType(Type componentType)
Creates an
ArrayType for the given component type. |
ArrayType |
substitute(Substitution substitution)
Applies a substitution to a
ReferenceType . |
applyCaptureConversion, getInstantiatingSubstitution, getInstantiatingSubstitutionforTypeVariable, isCaptureVariable, isInstantiationOf, isReferenceType
compareTo, forFullyQualifiedName, forName, forValue, getCanonicalName, getTypeforFullyQualifiedName, getUnqualifiedBinaryName, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isClassOrInterfaceType, isEnum, isGeneric, isInterface, isNonreceiverType, isObject, isParameterized, isPrimitive, isRawtype, isString, isVariable, isVoid, runtimeClassIs, toString
private final Type componentType
private final java.lang.Class<?> runtimeClass
private ArrayType(Type componentType, java.lang.Class<?> runtimeClass)
ArrayType
with the given component type and runtime class.componentType
- the component typeruntimeClass
- the runtime classpublic static ArrayType forClass(java.lang.Class<?> arrayClass)
java.lang.reflect.Class
object.arrayClass
- the Class
object for array typeArrayType
for the given class objectpublic static ArrayType forType(java.lang.reflect.Type type)
ArrayType
from a java.lang.reflect.Type
reference. First checks
whether reference has type java.lang.reflectGenericArrayType
, and if so performs the
conversion. If the reference is to a Class
object, then delegates to forClass(Class)
.type
- the Type
referenceType
for the array typepublic static ArrayType ofComponentType(Type componentType)
ArrayType
for the given component type. If the component type is a type
variable then creates a type with an Object
array as the rawtype.componentType
- the component typeArrayType
with the given component typepublic boolean equals(@Nullable java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public ArrayType substitute(Substitution substitution)
ReferenceType
ReferenceType
. If the type is parameterized then replaces
type variables that occur, otherwise returns this type.
This abstract method forces typing of substitutions applied to ReferenceType
objects
without an explicit cast.
substitute
in class ReferenceType
substitution
- the type substitutionpublic Type getComponentType()
public Type getElementType()
public java.lang.String getFqName()
Type
java.util.List<T>
return "java.util.List<T>"
.public java.lang.String getBinaryName()
Type
java.util.List<T>
return "java.util.List<T>"
.getBinaryName
in class Type
public java.lang.String getSimpleName()
Type
java.util.List<T>
, returns "List"
.getSimpleName
in class Type
@Pure public java.lang.Class<?> getRuntimeClass()
Type
Class
object for this type. For use when reflection is needed.
Note that type variables and the null reference type do not have a runtime class, and this method will return null in those cases.
This method should not be confused with the inherited Object.getClass()
method,
which returns the Class<?>
for the Type
object, and not of the represented
type. For instance, if a Type
object t
represented the Java type int
,
then t.getRuntimeClass()
would return int.class
while t.getClass()
would return Type.class
.
getRuntimeClass
in class Type
Class
that is the runtime representation of the type, or null if this type
is a type variable or null reference typepublic java.util.List<TypeVariable> getTypeParameters()
ReferenceType
ArrayType
(such as E[]
), and subclasses of ParameterizedType
.getTypeParameters
in class ReferenceType
public boolean isArray()
Type
public boolean isAssignableFrom(Type otherType)
Type
to this type.
(In other words, a value of the source type can be assigned to an l-value of this type.)
Returns true if this is a legal assignment conversion:
Variablethis = Expressionsourcetype.
Based on the definition of assignment context in section 5.2 of the Java Language Specification, a value of one type is assignable to a variable of another type if the first type can be converted to the second by
For assignment to ReferenceType
, checks for widening reference conversion when the
source type is also a reference type. See section JLS
5.1.5 for details.
For an array type, check for assignability by reference widening. If not otherwise
assignable, check for unchecked conversion, which occurs when this type is C<T1,...,Tk>[]
and other type is C[]
(e.g., the component type is the rawtype C
).
isAssignableFrom
in class ReferenceType
otherType
- the type to test for assignabilitypublic boolean isGeneric(boolean ignoreWildcards)
Type
public boolean isSubtypeOf(Type otherType)
For ReferenceType
, returns true if otherType
is Object
.
This method specifically uses the definition in section 4.10.2 of JLS for JavaSE 8.
isSubtypeOf
in class ReferenceType
otherType
- the possible supertypepublic Type getRawtype()
Type
getRawtype
in class Type
public boolean hasWildcard()
Type
hasWildcard
in class Type
public boolean hasCaptureVariable()
Type
ReferenceType
has a capture variable.hasCaptureVariable
in class Type
public boolean hasParameterizedElementType()
public ArrayType getRawTypeArray()
List<String>[]
to List[]
, List<String>[][]
to List[][]
, and int[]
to int[]
.public int getDimensions()