Class TypeReference<T>


  • public abstract class TypeReference<T>
    extends java.lang.Object
    A utility for getting a Java Type from a literal generic Class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.reflect.Type getType()
      Gets the referenced type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TypeReference

        public TypeReference()
        Creates a new instance of TypeReference. This class implements Super Type Tokens (Gafter's Gadget) as a way to get a reference to generic types in spite of type erasure since, sadly, Foo<Bar>.class is not valid Java. To get the Type of Class Foo<Bar>, use the following syntax:
        
         Type fooBarType = (new TypeReference<Foo<Bar>>() { }).getType();
         
        To get the Type of class Foo, use a regular Type Token:
        
         Type fooType = Foo.class;
         
        See Also:
        Super Type Tokens
    • Method Detail

      • getType

        public java.lang.reflect.Type getType()
        Gets the referenced type.
        Returns:
        The Type encapsulated by this TypeReference