Class TypeToken<T>

java.lang.Object
jakarta.config.TypeToken<T>
Type Parameters:
T - the modeled type; often parameterized

public abstract class TypeToken<T> extends Object
A holder of a modeled Type that embodies Gafter's gadget.

To use this class, create a new instance of an anonymous subclass of it, and then call type() on it. For example:

 // type will be a ParameterizedType whose rawType is List.class and
 // whose sole type argument is String.class
 Type type = new TypeToken<List<String>>() {}.type();
 assert type instanceof ParameterizedType;
 assert ((ParameterizedType)type).getRawType() == List.class;
 assert ((ParameterizedType)type).getActualTypeArguments()[0] == String.class;
See Also:
  • Constructor Details

    • TypeToken

      protected TypeToken()
      Creates a new TypeToken.
  • Method Details

    • type

      public final Type type()
      Returns the Type modeled by this TypeToken.

      This method never returns null.

      This method produces a determinate value.

      This method is idempotent.

      This method is safe for concurrent use by multiple threads.

      Returns:
      the Type modeled by this TypeToken; never null
    • erase

      public final Class<?> erase()
      Returns the type erasure of this TypeToken's modeled Type, or null if erasing the Type would result in a non-Class erasure (in which case the erasure is simply the Type itself), or if an erasure cannot be determined.

      This method never returns null.

      This method produces a determinate value.

      This method is idempotent.

      This method is safe for concurrent use by multiple threads.

      Returns:
      the type erasure of this TypeToken's modeled Type, or null if erasing the Type would result in a non-Class erasure, or if an erasure cannot be determined
    • hashCode

      public int hashCode()
      Returns a hashcode for this TypeToken computed from the Type it models.

      This method produces a determinate value.

      This method is idempotent.

      This method is safe for concurrent use by multiple threads.

      Overrides:
      hashCode in class Object
      Returns:
      a hashcode for this TypeToken
      See Also:
    • equals

      public boolean equals(Object other)
      Returns true if the supplied Object is equal to this TypeToken.

      This method returns true if the supplied Object's class is this TypeToken's class and if its modeled Type is equal to this TypeToken's modeled Type.

      This method produces a determinate value.

      This method is idempotent.

      This method is safe for concurrent use by multiple threads.

      Overrides:
      equals in class Object
      Parameters:
      other - the Object to test; may be null in which case false will be returned
      Returns:
      true if the supplied Object is equal to this TypeToken; false otherwise
      See Also:
    • toString

      public String toString()
      Returns a String representation of this TypeToken.

      This method returns a value equal to that returned by this.type().getTypeName().

      This method never returns null.

      This method produces a determinate value.

      This method is idempotent.

      This method is safe for concurrent use by multiple threads.

      Overrides:
      toString in class Object
      Returns:
      a String representation of this TypeToken; never null