我有以下案例
public class ResponseType <T> {
private ParameterizedTypeReference<HttpResponse<T>> type;
private ResponseType() {
this.type = new ParameterizedTypeReference<HttpResponse<T>>() {};
}
public static <T> ResponseType<T> create() {
return new ResponseType<T>();
}
}
当我致电ReponseType.<MyClass>create()
时,我如何构建ParameterizedTypeReference<HttpResponse<MyClass>>
?
目前,如果我调用它,则类型将为ParameterizedTypeReference<HttpResponse<T>>
我想做的是致电
restTemplate.exchange(
...,
responseType.getType()
);
其中responseType = ResponseType.create()
或resonseType = ResponseType.<MyClass>create()
而不是
restTemplate.exchange(
...,
new ParameterizedTypeReference<HttpResponse<MyClass>>() {}
);
答案 0 :(得分:0)
您正在create()调用的构造函数中创建,只要他键入T并在类中存储为&#39;键入&#39;
如果公开:
ParameterizedTypeReference<HttpResponse<MyClass>> obj = ReponseType.<MyClass>create().type;