Class TypeLiteral<T>

java.lang.Object
org.glassfish.hk2.api.TypeLiteral<T>
Type Parameters:
T -

public abstract class TypeLiteral<T> extends 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 subclassing TypeLiteral.
  TypeLiteral<List<String>> stringListType = new TypeLiteral<List<String>>() {};
 
  • Field Details

    • type

      private transient Type type
      Store the actual type (direct subclass of TypeLiteral).
    • rawType

      private transient Class<T> rawType
      Store the actual raw parameter type.
  • Constructor Details

    • TypeLiteral

      protected TypeLiteral()
  • Method Details

    • getType

      public final Type getType()
      Returns:
      the actual type represented by this object
    • getParameterTypes

      public final 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 Class<T> getRawType()
      Returns:
      the raw type represented by this object
    • getRawType

      public static Class<?> getRawType(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 Class<?> getTypeLiteralSubclass(Class<?> clazz)
      Return the direct child class that extends TypeLiteral
      Parameters:
      clazz - processed class
    • getTypeParameter

      private static Type getTypeParameter(Class<?> typeLiteralSubclass)
      Return the value of the type parameter of TypeLiteral.
      Parameters:
      typeLiteralSubclass - subClass of TypeLiteral to analyze
      Returns:
      the parametrized type of TypeLiteral (aka T)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object