Class TypeReference<T>

  • Type Parameters:
    T - The target type for the conversion.

    @ConsumerType
    public class TypeReference<T>
    extends Object
    An object does not carry any runtime information about its generic type. However sometimes it is necessary to specify a generic type, that is the purpose of this class. It allows you to specify an generic type by defining a type T, then subclassing it. The subclass will have a reference to the super class that contains this generic information. Through reflection, we pick this reference up and return it with the getType() call.
     List<String> result = converter.convert(Arrays.asList(1, 2, 3))
                    .to(new TypeReference<List<String>>() {});
     
    • Method Detail

      • getType

        public Type getType()
        Return the actual type of this Type Reference
        Returns:
        the type of this reference.