public abstract class ReferenceType extends Type
ReferenceType:
ClassOrInterfaceType
TypeVariable
ArrayType
This abstract type is used to mirror the grammar in the JLS.| Constructor and Description |
|---|
ReferenceType() |
| Modifier and Type | Method and Description |
|---|---|
ReferenceType |
applyCaptureConversion()
Applies a capture conversion to this type.
|
static ReferenceType |
forClass(java.lang.Class<?> classType)
Returns a
ReferenceType object for the given Class object. |
static ReferenceType |
forType(java.lang.reflect.Type type)
Creates a
ReferenceType for the given java.lang.reflect.Type. |
@Nullable Substitution |
getInstantiatingSubstitution(ReferenceType goalType)
Computes a substitution that can be applied to the type variables of the generic goal type to
instantiate operations of this type, possibly inherited from from the goal type.
|
static Substitution |
getInstantiatingSubstitutionforTypeVariable(ReferenceType instantiatedType,
ReferenceType goalType)
Static helper method that does the work of getInstantiatingSubstitution, if goalType is a type
variable.
|
java.util.List<TypeVariable> |
getTypeParameters()
Returns the list of type parameters for this type.
|
boolean |
isAssignableFrom(Type sourceType)
Indicates whether there is an assignment conversion from a source
Type to this type. |
boolean |
isCaptureVariable()
Indicates whether this type is a capture type variable as constructed by
InstantiatedType.applyCaptureConversion(). |
boolean |
isInstantiationOf(ReferenceType otherType)
Indicates whether this type is an instantiation of a more general type.
|
boolean |
isReferenceType()
Indicates whether this is a reference type.
|
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.
|
abstract ReferenceType |
substitute(Substitution substitution)
Applies a substitution to a
ReferenceType. |
compareTo, forFullyQualifiedName, forName, forValue, getBinaryName, getCanonicalName, getFqName, getRawtype, getRuntimeClass, getSimpleName, getTypeforFullyQualifiedName, getUnqualifiedBinaryName, hasCaptureVariable, hasWildcard, isArray, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isClassOrInterfaceType, isEnum, isGeneric, isGeneric, isInterface, isNonreceiverType, isObject, isParameterized, isPrimitive, isRawtype, isString, isVariable, isVoid, runtimeClassIs, toStringpublic static ReferenceType forClass(java.lang.Class<?> classType)
ReferenceType object for the given Class object. Creates arrays,
classes, and interfaces. For arrays, calls ArrayType.forClass(Class). For other
(class/interface) types, calls ClassOrInterfaceType.forClass(Class).classType - the Class object representing the typeReferenceType object for the given typepublic static ReferenceType forType(java.lang.reflect.Type type)
ReferenceType for the given java.lang.reflect.Type. Specifically,
creates
ArrayType if the reference is GenericArrayType or is a Class
object representing an array.
TypeVariable) if the reference is java.lang.reflect.TypeVariable.
ClassOrInterfaceType if the reference is none of those.
type - the type referenceReferenceType for the given Typepublic abstract ReferenceType substitute(Substitution substitution)
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 Typesubstitution - the type substitutionpublic ReferenceType applyCaptureConversion()
TypeapplyCaptureConversion in class Typepublic java.util.List<TypeVariable> getTypeParameters()
ArrayType (such as E[]), and subclasses of ParameterizedType.public boolean isAssignableFrom(Type sourceType)
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.
isAssignableFrom in class TypesourceType - the type to test for assignabilitypublic boolean isCaptureVariable()
InstantiatedType.applyCaptureConversion(). A capture type variable can only occur as a type
argument in an InstantiatedType constructed by InstantiatedType.applyCaptureConversion().public boolean isInstantiationOf(ReferenceType otherType)
For a general ReferenceType, this is only true if the other type is the same, or the
other type is a type variable for which this type satisfies the bounds. Other cases are handled
by the overriding implementations ClassOrInterfaceType.isInstantiationOf(ReferenceType), InstantiatedType.isInstantiationOf(ReferenceType), and TypeVariable.isInstantiationOf(ReferenceType).
otherType - the general reference typepublic @Nullable Substitution getInstantiatingSubstitution(ReferenceType goalType)
If there is no unifying substitution, returns null.
goalType - the generic type for which a substitution is neededpublic static Substitution getInstantiatingSubstitutionforTypeVariable(ReferenceType instantiatedType, ReferenceType goalType)
instantiatedType - the first typegoalType - the generic type for which a substitution is neededpublic boolean isReferenceType()
TypeisReferenceType in class Typepublic boolean isSubtypeOf(Type otherType)
For ReferenceType, returns true if otherType is Object.
isSubtypeOf in class TypeotherType - the possible supertype