public class TypeReference<T> extends Object implements Comparable<TypeReference<T>>
Comparable
(any such generic interface would do, as long as it forces a method
with generic type to be implemented).
to ensure that a Type argument is indeed given.
Usage is by sub-classing: here is one way to instantiate reference
to generic type List<Integer>
:
TypeReference ref = new TypeReference<List<Integer>>() { };
Modifier | Constructor and Description |
---|---|
protected |
TypeReference()
Constructs a new generic type, deriving the generic type and class from
type parameter.
|
|
TypeReference(Type typeReference)
Constructs a new generic type, supplying the generic type
information and deriving the class.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(TypeReference<T> o)
The only reason we define this method (and require implementation
of
Comparable ) is to prevent constructing a
reference without type information. |
boolean |
equals(Object obj) |
Class<?> |
getRawType()
Returns the object representing the class or interface that declared
the type represented by this generic type instance.
|
Type |
getType()
Retrieve the type represented by the generic type instance.
|
int |
hashCode() |
String |
toString() |
protected TypeReference()
IllegalArgumentException
- in case the generic type parameter value is not
provided by any of the subclasses.public TypeReference(Type typeReference)
typeReference
- the generic type.IllegalArgumentException
- if typeReference is null
or not an instance of
Class
or ParameterizedType
whose raw
type is an instance of Class
.public final Type getType()
public final Class<?> getRawType()
public int compareTo(TypeReference<T> o)
Comparable
) is to prevent constructing a
reference without type information.compareTo
in interface Comparable<TypeReference<T>>
Copyright © 2023. All rights reserved.