类 ParameterizedTypeReference<T>

  • 类型参数:
    T - the referenced type

    public abstract class ParameterizedTypeReference<T>
    extends 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.

    从以下版本开始:
    3.2
    作者:
    Arjen Poutsma, Rossen Stoyanchev
    另请参阅:
    Neal Gafter on Super Type Tokens