Class 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 subclassing TypeLiteral.
      TypeLiteral<List<String>> stringListType = new TypeLiteral<List<String>>() {};
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<T> rawType
      Store the actual raw parameter type.
      private java.lang.reflect.Type type
      Store the actual type (direct subclass of TypeLiteral).
    • 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 literal
      java.lang.Class<T> getRawType()  
      static java.lang.Class<?> getRawType​(java.lang.reflect.Type type)
      Gets the base associated class from this type
      java.lang.reflect.Type getType()  
      private static java.lang.Class<?> getTypeLiteralSubclass​(java.lang.Class<?> clazz)
      Return the direct child class that extends TypeLiteral
      private 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()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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.
    • Constructor Detail

      • TypeLiteral

        protected TypeLiteral()
    • 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 TypeLiteral to analyze
        Returns:
        the parametrized type of TypeLiteral (aka T)
      • 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