|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.googlecode.jtype.Generic<T>
T - the type that this generic type literal representspublic abstract class Generic<T>
Provides a generic type literal.
This class captures the actual type argument used when subclassed. This allows it to be referenced as a type parameter at compile time and also makes it available at run time. It is intended to be used as follows:
Generic<List<String>> listStringType = new Generic<List<String>>() {};
This allows generic type literals to be used in a simple manner as standard class literals. For example, consider the following generic method signature:
<T> void add(T element, Class<T> type)
A problem arises when <T> is a generic type, such as List<String>, since List<String>.class
produces a compile time error. Use of this class can mitigate this problem:
<T> void add(T element, Generic<T> type)
Which can then be invoked as follows:
add(new ArrayList<String>(), new Generic<List<String>>() {});
Generics,
Neal Gafter's blog: Super Type Tokens| Constructor Summary | |
|---|---|
protected |
Generic()
|
| Method Summary | ||
|---|---|---|
boolean |
equals(java.lang.Object object)
|
|
static
|
get(java.lang.Class<T> klass)
|
|
static
|
get(java.lang.Class<T> rawType,
java.lang.reflect.Type... actualTypeArguments)
|
|
static Generic<?> |
get(java.lang.reflect.Type type)
|
|
java.lang.Class<? super T> |
getRawType()
|
|
java.lang.reflect.Type |
getType()
|
|
int |
hashCode()
|
|
java.lang.String |
toString()
|
|
java.lang.String |
toUnqualifiedString()
|
|
static Generic<?> |
valueOf(java.lang.String typeName)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected Generic()
| Method Detail |
|---|
public java.lang.reflect.Type getType()
public java.lang.Class<? super T> getRawType()
public java.lang.String toUnqualifiedString()
public static <T> Generic<T> get(java.lang.Class<T> klass)
public static Generic<?> get(java.lang.reflect.Type type)
public static <T> Generic<? extends T> get(java.lang.Class<T> rawType,
java.lang.reflect.Type... actualTypeArguments)
public static Generic<?> valueOf(java.lang.String typeName)
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object object)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||