Class GenericType<T>

  • Type Parameters:
    T - the real type

    public abstract class GenericType<T>
    extends Object
    This class is a holder for generic types so we can work around type erasure. You can read this blog post who explains a bit more in details what it is about. For example if you want to use at runtime a List<Integer> :

     GenericType<List<Integer>> genericType = new GenericType<List<Integer>>() {
     };
     List<Integer> listOfIntegers = new Genson().deserialize("[1,2,3]", genericType);
    
     // if you want to get the standard java.lang.reflect.Type corresponding to List<Integer> from
     // genericType
     Type listOfIntegersType = genericType.getType();
     // listOfIntegersType will be an instance of ParameterizedType with Integer class as type argument
     
    Author:
    Eugen Cepoi