我正在将现有代码迁移到超类/子类情况。见下文。
家长班方法:
public <T> ResponseEntity<T> makeRequest(HttpMethod method, String endpoint, HttpEntity<?> request, Class<T> responseType) {
//DO stuff here
}
在子类中有对上面 makeRequest() 的调用。
ParameterizedTypeReference<List<MyOtherClass>> typeRef = new ParameterizedTypeReference<List<MyOtherClass>>() {};
ResponseEntity<List<MyOtherClass>> response = makeRequest(HttpMethod.GET,uriComponents.toUriString(), request, typeRef);
但最后一个论点似乎导致签名不匹配。Eclipse 是这么说的。
“ParentWS 类型中的方法 makeRequest(HttpMethod, String, HttpEntity, Class) 不适用于参数 (HttpMethod, String, HttpEntity, ParameterizedTypeReference>)”
我不明白为什么,父方法签名说任何类型的任何类。所有其他子类都只是简单地使用String.class调用父方法,就像这样。
response = makeRequest(HttpMethod.GET, healthCheckUrlEndpoint, request, String.class);
但是为什么ParameterizedTypeReference>() {}会导致问题?我以前从未使用过 ParameterizedTypeReference,它对我来说是全新的。请指教。