javax.ws.rs.core
Class TypeLiteral<T>

java.lang.Object
  extended by javax.ws.rs.core.TypeLiteral<T>
Type Parameters:
T - the generic type parameter.

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

Supports in-line instantiation of objects that represent parameterized types with actual type parameters. An object that represents any parameterized type may be obtained by sub-classing TypeLiteral.

  TypeLiteral<List<String>> stringListType = new TypeLiteral<List<String>>() {};
 

Since:
2.0
Author:
Jerome Dochez, Marek Potociar

Constructor Summary
protected TypeLiteral()
          Protected constructor for a type literal of a concrete Java type.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 java.lang.reflect.Type[] getParameterTypes()
          Retrieve an array of Type objects representing the actual type arguments to the type represented by this type literal.
 java.lang.Class<T> getRawType()
          Returns the object representing the class or interface that declared the type represented by this type literal instance.
 java.lang.reflect.Type getType()
          Retrieve the type represented by the type literal instance.
 int hashCode()
           
static
<T> TypeLiteral<T>
of(java.lang.Class<?> rawType, java.lang.reflect.Type type)
          Construct a type literal instance with programmatically set values of type and raw type.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TypeLiteral

protected TypeLiteral()
Protected constructor for a type literal of a concrete Java type.

Method Detail

of

public static <T> TypeLiteral<T> of(java.lang.Class<?> rawType,
                                    java.lang.reflect.Type type)
Construct a type literal instance with programmatically set values of type and raw type.

Type Parameters:
T - Java type.
Parameters:
rawType - raw parameter type.
type - parameter type (possibly generic).
Returns:
programmatically constructed type literal instance.

getType

public final java.lang.reflect.Type getType()
Retrieve the type represented by the type literal instance.

Returns:
the actual type represented by this type literal instance.

getParameterTypes

public final java.lang.reflect.Type[] getParameterTypes()
Retrieve an array of Type objects representing the actual type arguments to the type represented by this type literal.

Note that in some cases, the returned array may be empty. This can occur if the type represented by this type literal is a non-parameterized type.

Returns:
an array of Type objects representing the actual type arguments to this type.
Throws:
java.lang.TypeNotPresentException - if any of the actual type arguments refers to a non-existent type declaration.
java.lang.reflect.MalformedParameterizedTypeException - if any of the actual type parameters refer to a parameterized type that cannot be instantiated for any reason.

getRawType

public final java.lang.Class<T> getRawType()
Returns the object representing the class or interface that declared the type represented by this type literal instance.

Returns:
the class or interface that declared the type represented by this type literal instance.

equals

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

hashCode

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

toString

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


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.