org.springframework.core

Class ParameterizedTypeReference<T>

  • java.lang.Object
    • org.springframework.core.ParameterizedTypeReference<T>
  • Type Parameters:
    T - the referenced type


    public abstract class ParameterizedTypeReference<T>
    extends java.lang.Object
    The purpose of this class is to enable capturing and passing a generic Type. In order to capture the generic type and retain it at runtime, you need to create a subclass (ideally as anonymous inline class) as follows:
     ParameterizedTypeReference<List<String>> typeRef = new ParameterizedTypeReference<List<String>>() {};
     

    The resulting typeRef instance can then be used to obtain a Type instance that carries the captured parameterized type information at runtime. For more information on "super type tokens" see the link to Neal Gafter's blog post.

    Since:
    3.2
    Author:
    Arjen Poutsma, Rossen Stoyanchev
    See Also:
    Neal Gafter on Super Type Tokens
    • Constructor Detail

      • ParameterizedTypeReference

        protected ParameterizedTypeReference()
    • Method Detail

      • getType

        public java.lang.reflect.Type getType()
      • equals

        public boolean equals(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • forType

        public static <T> ParameterizedTypeReference<T> forType(java.lang.reflect.Type type)
        Build a ParameterizedTypeReference wrapping the given type.
        Parameters:
        type - a generic type (possibly obtained via reflection, e.g. from Method.getGenericReturnType())
        Returns:
        a corresponding reference which may be passed into ParameterizedTypeReference-accepting methods
        Since:
        4.3.12