com.google.inject
Class TypeToken<T>

java.lang.Object
  extended by com.google.inject.TypeToken<T>

public abstract class TypeToken<T>
extends java.lang.Object

Represents a generic type T.

Assumes Type implements equals() and hashCode() as a value (as opposed to identity) comparison.

Author:
crazybob@google.com (Bob Lee)

Constructor Summary
protected TypeToken()
          Constructs a new type token.
 
Method Summary
 boolean equals(java.lang.Object o)
           
static
<T> TypeToken<T>
get(java.lang.Class<T> type)
          Gets type token for the given Class instance.
static TypeToken<?> get(java.lang.reflect.Type type)
          Gets type token for the given Type instance.
 java.lang.reflect.Type getType()
          Gets underlying Type instance.
 int hashCode()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TypeToken

protected TypeToken()
Constructs a new type token. 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.

For example: TypeToken<List<String>> t = new TypeToken<List<String>>() {};

Method Detail

getType

public java.lang.reflect.Type getType()
Gets underlying Type instance.


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

get

public static TypeToken<?> get(java.lang.reflect.Type type)
Gets type token for the given Type instance.


get

public static <T> TypeToken<T> get(java.lang.Class<T> type)
Gets type token for the given Class instance.