org.apache.pivot.util
Class TypeLiteral<T>

java.lang.Object
  extended by org.apache.pivot.util.TypeLiteral<T>
Type Parameters:
T - note that in Tree the type parameter currently it's not used

public class TypeLiteral<T>
extends Object

Represents a generic type T. Java doesn't yet provide a way to represent generic types, so this class does. Clients create a subclass of this class, which enables retrieval 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>>() &#123;&#125;).getType();

This class is a drastically reduced derivation from Google Guice's TypeLiteral class, written by Bob Lee and Jesse Wilson.


Constructor Summary
protected TypeLiteral()
          Constructs a new type literal.
 
Method Summary
 Type getType()
          Gets underlying Type instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

Method Detail

getType

public final Type getType()
Gets underlying Type instance.