public class NonParameterizedType extends ClassOrInterfaceType
NonParameterizedType
represents a non-parameterized class, interface, enum, or the
rawtype of a generic class. It is a wrapper for a Class
object, which is a runtime
representation of a type.Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,NonParameterizedType> |
cache
A cache of all NonParameterizedTypes that have been created.
|
private java.lang.Class<?> |
runtimeType
The runtime class of this simple type.
|
enclosingType
Constructor and Description |
---|
NonParameterizedType(java.lang.Class<?> runtimeType)
Create a
NonParameterizedType object for the runtime class. |
Modifier and Type | Method and Description |
---|---|
NonParameterizedType |
applyCaptureConversion()
Applies a capture conversion to this type.
|
boolean |
equals(@Nullable java.lang.Object obj) |
static NonParameterizedType |
forClass(java.lang.Class<?> runtimeType)
Create a
NonParameterizedType object for the runtime class. |
private java.util.List<ClassOrInterfaceType> |
getGenericInterfaces()
Returns the list of direct interfaces for this class.
|
java.util.List<ClassOrInterfaceType> |
getInterfaces()
Returns the interface types directly implemented by this class or interface type.
|
NonParameterizedType |
getRawtype()
Returns the non-parameterized form of this class type.
|
private java.util.List<ClassOrInterfaceType> |
getRawTypeInterfaces()
Returns the list of rawtypes for the direct interfaces for this type.
|
java.lang.Class<?> |
getRuntimeClass()
Returns the runtime
Class object for this type. |
ClassOrInterfaceType |
getSuperclass()
Return the type for the superclass for this class.
|
int |
hashCode() |
boolean |
isAbstract()
Indicate whether this class is abstract.
|
boolean |
isAssignableFrom(Type sourceType)
Indicates whether there is an assignment conversion from a source
Type to this type. |
boolean |
isBoxedPrimitive()
Indicates whether this is a boxed primitive type.
|
boolean |
isEnum()
Indicates whether this is an enum type.
|
boolean |
isInstantiationOf(ReferenceType otherType)
Indicates whether this type is an instantiation of a more general type.
|
boolean |
isInterface()
Indicates whether this object is an interface type.
|
boolean |
isRawtype()
Indicate whether this type is a rawtype of a generic class.
|
boolean |
isStatic()
Indicates whether this class is static.
|
NonParameterizedType |
substitute(Substitution substitution)
Applies a substitution to a
ReferenceType . |
PrimitiveType |
toPrimitive()
If this type is a boxed primitive, unboxes this type and returns the primitive type.
|
applyCaptureConversion, forType, getAllSupertypesInclusive, getBinaryName, getCanonicalName, getFqName, getImmediateSupertypes, getInstantiatingSubstitution, getMatchingSupertype, getPackage, getPackagePrefix, getSimpleName, getSuperTypes, getTypeArguments, getTypeParameters, getUnqualifiedBinaryName, hasCaptureVariable, hasWildcard, isClassOrInterfaceType, isGeneric, isMemberClass, isNestedClass, isParameterized, isSubtypeOf, substitute
getInstantiatingSubstitutionforTypeVariable, isCaptureVariable, isReferenceType
compareTo, forFullyQualifiedName, forName, forValue, getTypeforFullyQualifiedName, isArray, isAssignableFromTypeOf, isClass, isGeneric, isNonreceiverType, isObject, isPrimitive, isString, isVariable, isVoid, runtimeClassIs, toString
private final java.lang.Class<?> runtimeType
private static final java.util.Map<java.lang.Class<?>,NonParameterizedType> cache
public NonParameterizedType(java.lang.Class<?> runtimeType)
NonParameterizedType
object for the runtime class.runtimeType
- the runtime class for the typepublic static NonParameterizedType forClass(java.lang.Class<?> runtimeType)
NonParameterizedType
object for the runtime class.runtimeType
- the runtime class for the typepublic boolean equals(@Nullable java.lang.Object obj)
equals
in class ClassOrInterfaceType
public int hashCode()
hashCode
in class ClassOrInterfaceType
public NonParameterizedType substitute(Substitution substitution)
ClassOrInterfaceType
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.
This abstract method allows substitutions to be applied to ClassOrInterfaceType
objects without casting.
substitute
in class ClassOrInterfaceType
substitution
- the type substitutionpublic NonParameterizedType applyCaptureConversion()
Type
applyCaptureConversion
in class ClassOrInterfaceType
public java.util.List<ClassOrInterfaceType> getInterfaces()
ClassOrInterfaceType
Class.getGenericInterfaces()
. If no interfaces are
implemented, then returns the empty list.getInterfaces
in class ClassOrInterfaceType
private java.util.List<ClassOrInterfaceType> getGenericInterfaces()
public NonParameterizedType getRawtype()
ClassOrInterfaceType
getRawtype
in class ClassOrInterfaceType
private java.util.List<ClassOrInterfaceType> getRawTypeInterfaces()
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 ClassOrInterfaceType getSuperclass()
ClassOrInterfaceType
getSuperclass
in class ClassOrInterfaceType
Object
type if this type has no superclasspublic boolean isAbstract()
ClassOrInterfaceType
isAbstract
in class ClassOrInterfaceType
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.
Specifically checks for boxing conversion (section 5.1.7)
isAssignableFrom
in class ReferenceType
sourceType
- the type to test for assignabilitypublic boolean isBoxedPrimitive()
Type
isBoxedPrimitive
in class Type
public boolean isEnum()
Type
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)
.
For a ClassOrInterfaceType
that is a member class, if otherType
is also a
member class, then the enclosing type of this type must instantiate the enclosing type of
otherType
.
For a NonParameterizedType
, if this type instantiates the otherType
, which
is a NonParameterizedType
by ClassOrInterfaceType.isInstantiationOf(ReferenceType)
also checks that runtime classes are
equal. This allows for proper matching of member classes that are of NonParameterizedType
.
isInstantiationOf
in class ClassOrInterfaceType
otherType
- the general reference typepublic boolean isInterface()
Type
isInterface
in class Type
public boolean isRawtype()
Type
public boolean isStatic()
ClassOrInterfaceType
isStatic
in class ClassOrInterfaceType
public PrimitiveType toPrimitive()
java.lang.IllegalArgumentException
- if this is not a boxed primitive type