T. Java doesn't yet provide a way to represent generic types,
so this class does. Forces clients to create a subclass of this class which enables retrieval of
the type information even at runtime.
For example, to create a type literal for List<String>, you can create an empty
anonymous inner class:
TypeLiteral<List<String>> list = new TypeLiteral<List<String>>() {};
Along with modeling generic types, this class can resolve type parameters. For example, to
figure out what type keySet() returns on a Map<Integer, String>, use this code:
TypeLiteral<Map<Integer, String>> mapType
= new TypeLiteral<Map<Integer, String>>() {};
TypeLiteral<?> keySetType
= mapType.getReturnType(Map.class.getMethod("keySet"));
System.out.println(keySetType); // prints "Set<Integer>"
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final int | |
| pack-priv final Class | |
| pack-priv final Type |
| Access | Constructor and Description |
|---|---|
| protected | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public final boolean | equals(Object
the reference object with which to compare. o)Overrides java. |
| pack-priv static TypeLiteral | |
| public static TypeLiteral | |
| public static <T> TypeLiteral | |
| public List | getExceptionTypes(Member
a method or constructor defined by this or any supertype. methodOrConstructor)Returns the resolved generic exception types thrown by |
| public TypeLiteral | getFieldType(Field
a field defined by this or any superclass. field)Returns the resolved generic type of |
| public List | getParameterTypes(Member
a method or constructor defined by this or any supertype. methodOrConstructor)Returns the resolved generic parameter types of |
| public final Class | |
| public TypeLiteral | getReturnType(Method
a method defined by this or any supertype. method)Returns the resolved generic return type of |
| pack-priv static Type | getSuperclassTypeParameter(Class<?> subclass)
Returns the type from super class's type parameter in |
| public TypeLiteral | getSupertype(Class<?>
a superclass of, or interface implemented by, this. supertype)Returns the generic form of |
| public final Type | |
| public final int | |
| pack-priv final TypeLiteral | |
| pack-priv TypeLiteral | |
| private List | |
| pack-priv Type | |
| public final String |
| hashCode | back to summary |
|---|---|
| pack-priv final int hashCode | |
| rawType | back to summary |
|---|---|
| pack-priv final Class<? super T> rawType | |
| type | back to summary |
|---|---|
| pack-priv final Type type | |
| TypeLiteral | back to summary |
|---|---|
| protected TypeLiteral() Constructs a new type literal. Derives represented class from type parameter. Clients create an empty anonymous subclass. Doing so embeds the type parameter in the anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure.
| |
| TypeLiteral | back to summary |
|---|---|
| pack-priv TypeLiteral(Type type) Unsafe. Constructs a type literal manually.
| |
| equals | back to summary |
|---|---|
| public final boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| fromSuperclassTypeParameter | back to summary |
|---|---|
| pack-priv static TypeLiteral Gets type literal from super class's type parameter. | |
| get | back to summary |
|---|---|
| public static TypeLiteral Gets type literal for the given | |
| get | back to summary |
|---|---|
| public static <T> TypeLiteral Gets type literal for the given | |
| getExceptionTypes | back to summary |
|---|---|
| public List Returns the resolved generic exception types thrown by
| |
| getFieldType | back to summary |
|---|---|
| public TypeLiteral Returns the resolved generic type of
| |
| getParameterTypes | back to summary |
|---|---|
| public List Returns the resolved generic parameter types of
| |
| getRawType | back to summary |
|---|---|
| public final Class Returns the raw (non-generic) type for this type.
| |
| getReturnType | back to summary |
|---|---|
| public TypeLiteral Returns the resolved generic return type of
| |
| getSuperclassTypeParameter | back to summary |
|---|---|
| pack-priv static Type getSuperclassTypeParameter(Class<?> subclass) Returns the type from super class's type parameter in | |
| getSupertype | back to summary |
|---|---|
| public TypeLiteral Returns the generic form of
| |
| getType | back to summary |
|---|---|
| public final Type getType() Gets underlying | |
| hashCode | back to summary |
|---|---|
| public final int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| providerType | back to summary |
|---|---|
| pack-priv final TypeLiteral Gets the type of this type's provider.
| |
| resolve | back to summary |
|---|---|
| pack-priv TypeLiteral Resolves known type parameters in | |
| resolveAll | back to summary |
|---|---|
| private List Returns an immutable list of the resolved types. | |
| resolveType | back to summary |
|---|---|
| pack-priv Type resolveType(Type toResolve) | |
| toString | back to summary |
|---|---|
| public final String toString() Overrides java. Doc from java. Returns a string representation of the object. | |