Package org.glassfish.hk2.api
Class TypeLiteral<T>
- java.lang.Object
-
- org.glassfish.hk2.api.TypeLiteral<T>
-
- Type Parameters:
T
-
public abstract class TypeLiteral<T> extends java.lang.Object
Supports inline instantiation of objects that represent parameterized types with actual type parameters. An object that represents any parameterized type may be obtained by subclassingTypeLiteral
.TypeLiteral<List<String>> stringListType = new TypeLiteral<List<String>>() {};
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TypeLiteral()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.lang.reflect.Type[]
getParameterTypes()
Gets the types associated with this literaljava.lang.Class<T>
getRawType()
static java.lang.Class<?>
getRawType(java.lang.reflect.Type type)
Gets the base associated class from this typejava.lang.reflect.Type
getType()
private static java.lang.Class<?>
getTypeLiteralSubclass(java.lang.Class<?> clazz)
Return the direct child class that extends TypeLiteralprivate static java.lang.reflect.Type
getTypeParameter(java.lang.Class<?> typeLiteralSubclass)
Return the value of the type parameter of TypeLiteral. int
hashCode()
java.lang.String
toString()
-
-
-
Field Detail
-
type
private transient java.lang.reflect.Type type
Store the actual type (direct subclass of TypeLiteral).
-
rawType
private transient java.lang.Class<T> rawType
Store the actual raw parameter type.
-
-
Method Detail
-
getType
public final java.lang.reflect.Type getType()
- Returns:
- the actual type represented by this object
-
getParameterTypes
public final java.lang.reflect.Type[] getParameterTypes()
Gets the types associated with this literal- Returns:
- A non-null (but possibly empty) array of types associated with this literal
-
getRawType
public final java.lang.Class<T> getRawType()
- Returns:
- the raw type represented by this object
-
getRawType
public static java.lang.Class<?> getRawType(java.lang.reflect.Type type)
Gets the base associated class from this type- Parameters:
type
- The non-null type to analyze- Returns:
- The base class for the type, or null if there is none (e.g., Wildcard)
-
getTypeLiteralSubclass
private static java.lang.Class<?> getTypeLiteralSubclass(java.lang.Class<?> clazz)
Return the direct child class that extends TypeLiteral- Parameters:
clazz
- processed class
-
getTypeParameter
private static java.lang.reflect.Type getTypeParameter(java.lang.Class<?> typeLiteralSubclass)
Return the value of the type parameter of TypeLiteral. - Parameters:
typeLiteralSubclass
- subClass of TypeLiteralto analyze - Returns:
- the parametrized type of TypeLiteral
(aka T)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-