Class object of generic class (java)

前端 未结 7 949
时光说笑
时光说笑 2020-11-27 03:17

is there a way in java to get an instance of something like Class> ?

7条回答
  •  醉梦人生
    2020-11-27 03:17

    You could use Jackson's ObjectMapper

    ObjectMapper objectMapper = new ObjectMapper();
    CollectionType listType = objectMapper.getTypeFactory().constructCollectionType(List.class, ElementClass.class)
    

    No unchecked warnings, no empty List instances floating around.

提交回复
热议问题