Java 从泛型类型获取类
我如何调用.class或如何从以下泛型类型获取类Java 从泛型类型获取类,java,generics,Java,Generics,我如何调用.class或如何从以下泛型类型获取类 headerMap.put("accept", MediaType.APPLICATION_JSON_VALUE); ResponseEntity<PaginationResponse<Category>> response = restClient.getResource(url, headerMap, **PaginationResponse<Category>.class**);
headerMap.put("accept", MediaType.APPLICATION_JSON_VALUE);
ResponseEntity<PaginationResponse<Category>> response =
restClient.getResource(url, headerMap, **PaginationResponse<Category>.class**);
LOGGER.info("Method getAllCategories() - END");
headerMap.put(“接受”,MediaType.APPLICATION\u JSON\u值);
反应性反应=
getResource(url,headerMap,**PaginationResponse.class**);
info(“方法getAllCategories()-END”);
它显示错误,据我所知,该信息在运行时不可用。
但也许,您可以使用。中的一些想法,据我所知,这些信息在运行时不可用。 但是,也许你可以使用一些来自的想法。不,你不能 泛型类型T不会在运行时保留,因为 然而,如果你仍然想这样做
public class Foo<T>
{
private Class<T> type;
public Foo(Class<T> type) {
this.type = type;
}
}
公共类Foo
{
私人阶级类型;
公共Foo(类类型){
this.type=type;
}
}
不,您不能
泛型类型T不会在运行时保留,因为
然而,如果你仍然想这样做
public class Foo<T>
{
private Class<T> type;
public Foo(Class<T> type) {
this.type = type;
}
}
公共类Foo
{
私人阶级类型;
公共Foo(类类型){
this.type=type;
}
}
我将此解决方案用于泛型类型类
Spring实现用于Rest模板我将此解决方案用于泛型类型类
Spring实现是针对Rest模板的这是Java中缺少的东西,称为物化。这是Java中缺少的东西,称为物化。