public abstract class TypeVariable extends ParameterType
Constructor and Description |
---|
TypeVariable()
Creates a type variable with
NullReferenceType as the lower bound, and the Object type as upper bound. |
TypeVariable(ParameterBound lowerBound,
ParameterBound upperBound)
Creates a type variable with the given type bounds.
|
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
canBeInstantiatedBy(ReferenceType otherType)
Indicates whether this
TypeVariable can be instantiated by the ReferenceType . |
abstract TypeVariable |
createCopyWithBounds(ParameterBound lowerBound,
ParameterBound upperBound) |
static TypeVariable |
forType(java.lang.reflect.Type type)
Creates a
TypeVariable object for a given java.lang.reflect.Type reference,
which must be a java.lang.reflect.TypeVariable . |
Type |
getRawtype()
Returns the raw type for this type, which is this type except for generic types.
|
private static Substitution |
getSubstitution(TypeVariable variable,
ReferenceType otherType)
Creates a substitution of the given
ReferenceType for the TypeVariable . |
java.util.List<TypeVariable> |
getTypeParameters()
Returns the type parameters in this type, which is this variable.
|
boolean |
isAssignableFrom(Type sourceType)
Indicates whether there is an assignment conversion from a source
Type to this type. |
boolean |
isInstantiationOf(ReferenceType otherType)
Indicates whether this type is an instantiation of a more general 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.
|
boolean |
isVariable()
Indicates whether this type is a type variable.
|
ReferenceType |
substitute(Substitution substitution)
Applies a substitution to a
ReferenceType . |
java.lang.String |
toString() |
equals, getCanonicalName, getLowerTypeBound, getRuntimeClass, getUpperTypeBound, hasCaptureVariable, hasGenericBound, hashCode, hasWildcard, setLowerBound, setUpperBound
applyCaptureConversion, forClass, getInstantiatingSubstitution, getInstantiatingSubstitutionforTypeVariable, isCaptureVariable, isReferenceType
compareTo, forFullyQualifiedName, forName, forValue, getBinaryName, getFqName, getSimpleName, getTypeforFullyQualifiedName, getUnqualifiedBinaryName, isArray, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isClassOrInterfaceType, isEnum, isGeneric, isGeneric, isInterface, isNonreceiverType, isObject, isParameterized, isPrimitive, isRawtype, isString, isVoid, runtimeClassIs
TypeVariable()
NullReferenceType
as the lower bound, and the Object
type as upper bound.TypeVariable(ParameterBound lowerBound, ParameterBound upperBound)
lowerBound
- the lower type bound on this variableupperBound
- the upper type bound on this variablepublic static TypeVariable forType(java.lang.reflect.Type type)
TypeVariable
object for a given java.lang.reflect.Type
reference,
which must be a java.lang.reflect.TypeVariable
.type
- the type referenceTypeVariable
for the given typepublic ReferenceType 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 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.
Returns false, since an uninstantiated type variable may not be assigned to.
isAssignableFrom
in class ReferenceType
sourceType
- the type to test for assignabilitypublic boolean isInstantiationOf(ReferenceType otherType)
ReferenceType
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 isInstantiationOf(ReferenceType)
.
isInstantiationOf
in class ReferenceType
otherType
- the general reference typepublic boolean isSubtypeOf(Type otherType)
ReferenceType
For ReferenceType
, returns true if otherType
is Object
.
isSubtypeOf
in class ReferenceType
otherType
- the possible supertypeprivate static Substitution getSubstitution(TypeVariable variable, ReferenceType otherType)
ReferenceType
for the TypeVariable
.variable
- the variableotherType
- the replacement typevariable
with otherType
public boolean isVariable()
Type
isVariable
in class Type
boolean canBeInstantiatedBy(ReferenceType otherType)
TypeVariable
can be instantiated by the ReferenceType
.
Does not require that all bounds of this variable be instantiated.otherType
- the possibly instantiating type, not a variablepublic java.util.List<TypeVariable> getTypeParameters()
getTypeParameters
in class ParameterType
public abstract TypeVariable createCopyWithBounds(ParameterBound lowerBound, ParameterBound upperBound)
public Type getRawtype()
Type
getRawtype
in class Type
public java.lang.String toString()
toString
in class ParameterType