Package org.apache.pivot.util
Class TypeLiteral<T>
- java.lang.Object
-
- org.apache.pivot.util.TypeLiteral<T>
-
- Type Parameters:
T
- note that in Tree the type parameter currently is not used
public class TypeLiteral<T> extends java.lang.Object
Represents a generic typeT
. Java doesn't yet provide a way to represent generic types, so this class does. Clients create a subclass of this class, which enables retrieving the type information even at runtime.For example, to get a reference to a generic type
List<String>
, you create an empty anonymous inner class, like so:Type genericType = (new TypeLiteral<List<String>>(){}).getType();
This class is a drastically reduced derivation from Google Guice's
TypeLiteral
class, written by Bob Lee and Jesse Wilson.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TypeLiteral()
Constructs a new type literal.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.reflect.Type
getType()
Gets underlyingType
instance.
-
-
-
Constructor Detail
-
TypeLiteral
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.
-
-