Class TypeToken<T>

  • Type Parameters:
    T - Represented type

    public class TypeToken<T>
    extends Object
    Represents a generic type T. Subclassing TypeToken allows for type information to be preserved at runtime.

    Example: To create a type literal for List<String>, you can create an empty anonymous inner class:

    TypeToken<List<String>> list = new TypeToken<List<String>>();

    • Constructor Detail

      • TypeToken

        protected TypeToken()
        Creates a new type token for T.
        Throws:
        IllegalArgumentException - if T is not provided or is a TypeVariable
    • Method Detail

      • getType

        public final Type getType()
        Returns the generic type T.
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object