JType 0.1.1-redhat-2

com.googlecode.jtype
Class Generic<T>

java.lang.Object
  extended by com.googlecode.jtype.Generic<T>
Type Parameters:
T - the type that this generic type literal represents

public abstract class Generic<T>
extends Object

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>>() {});

Version:
$Id: Generic.java 47 2009-10-02 15:59:23Z markhobson $
Author:
Mark Hobson
See Also:
Generics, Neal Gafter's blog: Super Type Tokens

Constructor Summary
protected Generic()
           
 
Method Summary
 boolean equals(Object object)
          
static
<T> Generic<T>
get(Class<T> klass)
           
static
<T> Generic<? extends T>
get(Class<T> rawType, Type... actualTypeArguments)
           
static Generic<?> get(Type type)
           
 Class<? super T> getRawType()
           
 Type getType()
           
 int hashCode()
          
 String toString()
          
 String toUnqualifiedString()
           
static Generic<?> valueOf(String typeName)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Generic

protected Generic()
Method Detail

getType

public Type getType()

getRawType

public Class<? super T> getRawType()

toUnqualifiedString

public String toUnqualifiedString()

get

public static <T> Generic<T> get(Class<T> klass)

get

public static Generic<?> get(Type type)

get

public static <T> Generic<? extends T> get(Class<T> rawType,
                                           Type... actualTypeArguments)

valueOf

public static Generic<?> valueOf(String typeName)

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object object)

Overrides:
equals in class Object

toString

public String toString()

Overrides:
toString in class Object

JType 0.1.1-redhat-2

Copyright © 2008-2012 JBoss by Red Hat. All Rights Reserved.