Class TypeReference<T>

java.lang.Object
is.codion.common.utilities.TypeReference<T>
Type Parameters:
T - the type represented by this type reference.

public abstract class TypeReference<T> extends Object
A basic TypeReference implementation, capturing a generic type via an anonymous subclass:
 TypeReference<List<String>> reference = new TypeReference<>() {};

The captured type T must itself be a parameterized type; for plain classes use the available Class<T> based overloads instead. A non-parameterized T (e.g. new TypeReference<String>() {}) throws IllegalArgumentException.

  • Constructor Details

    • TypeReference

      protected TypeReference()
      Instantiates a new TypeReference
      Throws:
      IllegalArgumentException - in case the subclass is raw (no type argument) or T is not a parameterized type
  • Method Details

    • type

      public final Type type()
      Returns:
      the type
    • rawType

      public final Class<T> rawType()
      Returns:
      the generic class type
    • hashCode

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

      public final boolean equals(Object object)
      Overrides:
      equals in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object