how can I call .class Or how can I get class from following generic type
headerMap.put("accept", MediaType.APPLICATION_JSON_VALUE);
ResponseEntity<PaginationResponse<Category>> response =
restClient.getResource(url, headerMap, **PaginationResponse<Category>.class**);
LOGGER.info("Method getAllCategories() - END");
It shows error
As far as I know the information is not avaiable at runtime. But perhaps, you can use some ideas from Get generic type of class at runtime .
No, you cannot.
The generic type T is not kept at runtime because of Type Erasure .
However, if you still want to do it
public class Foo<T>
{
private Class<T> type;
public Foo(Class<T> type) {
this.type = type;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.