- All Implemented Interfaces:
Type
Type interfaces, with methods
for a couple useful manipulations.
The implementations returned from Java reflection methods are internal, with no way to instantiate arbitrary new ones to represent the results of computations with them.
Note: the implementations here do not override equals and
hashCode inherited from Object. The JDK internal ones do,
but not with documented behaviors, so it didn't seem worthwhile to try
to match them. (The API specifies an equals behavior only for
ParameterizedType, and no corresponding hashCode even for
that, so good luck matching it.) Results from methods in this class can
include new objects (instances of these classes) and original ones
constructed by Java; don't assume anything sane will happen using
equals or hashCode between them. There is a
typesEqual static method defined here to do that job.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA class recording the bindings made in a ParameterizedType to the type parameters in a GenericDeclaration<Class>.static classA class dedicated to manipulating the types of multidimensional Java arrays, and their instances, that conform to PostgreSQL array constraints (non-'jagged', each dimension's arrays all equal size, no intermediate nulls). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> Returns the erasure of a type.static TypeVariable<?>[]static booleanNeeded: test whether sub is a subtype of sup.static Type[]Refines someTypes in by unifying the first of them with using.static Type[]specialization(Type candidate, Class<?> expected) Equivalent tospecialization(candidate, expected, null).static Type[]specialization(Type candidate, Class<?> expected, Type[] rtype) Test whether the typecandidateis, directly or indirectly, a specialization of generic typeexpected.static TypeRecursively descend t substituting any occurrence of a type variable found in b, returning a new object, or t unchanged if no substitutions were made.
-
Constructor Details
-
AbstractType
public AbstractType()
-
-
Method Details
-
refine
Refines someTypes in by unifying the first of them with using.The variadic array of in arguments is returned, modified in place.
The type using is unified with
in[0]and then used to replacein[0], while any variable substitutions made in the unification are repeated in the remaining in elements. -
isSubtype
Needed: test whether sub is a subtype of sup.XXX For the time being, this is nothing but a test of erased subtyping, hastily implemented by requiring that
specialization(sub, erase(sup))does not return null.This must sooner or later be replaced with an implementation of the subtyping rules from Java Language Specification 4.10, taking also type parameterization into account.
-
specialization
Equivalent tospecialization(candidate, expected, null). -
specialization
Test whether the typecandidateis, directly or indirectly, a specialization of generic typeexpected.For example, the Java type T of a particular adapter A that extends
Adapter.As<T,?>can be retrieved withspecialization(A.class, As.class)[0].More generally, this method can retrieve the generic type information from any "super type token", as first proposed by Neal Gafter in 2006, where a super type token is generally an instance of an anonymous subclass that specializes a certain generic type. Although the idea has been often used, the usages have not settled on one agreed name for the generic type. This method will work with any of them, by supplying the expected generic type itself as the second parameter. For example, a super type token
fooderived from Gafter's suggested classTypeReferencecan be unpacked withspecialization(foo.getClass(), TypeReference.class).- Parameters:
candidate- a type to be checkedexpected- known (normally generic) type to check forrtype- array to receive (if non-null) the corresponding (parameterized or raw) type if the result is non-null.- Returns:
- null if candidate does not extend expected, otherwise the array of type arguments with which it specializes expected
- Throws:
IllegalArgumentException- if passed a Type that is not a Class or a ParameterizedTypeNullPointerException- if either argument is nullUnsupportedOperationException- if candidate does extend expected but does not carry the needed parameter bindings (such as when the raw expected Class itself is passed)
-
erase
Returns the erasure of a type.If t is a
Class, it is returned unchanged. -
substitute
Recursively descend t substituting any occurrence of a type variable found in b, returning a new object, or t unchanged if no substitutions were made.Currently throws
UnsupportedOperationExceptionif t is a wildcard, as that case shouldn't be needed for the analysis of class/interface inheritance hierarchies thatspecializationis concerned with. -
freeVariables
-
getTypeName
- Specified by:
getTypeNamein interfaceType
-