我所试图做的事:声明泛型类型<?>
getMapType(String.class,String.class); //returns me a MapType of Map<String,String>
我已经试过:
public static <K extends Class<?>, V extends Class<?>> MapType getMapType(K keyClass, V valueClass) {
return objectMapper.getTypeFactory().constructMapType(HashMap.class, keyClass,valueClass);
}
声明K,V时,这给了我一个警告正在扩大班级。
The type parameter V should not be bounded by the final type Class<?>. Final types cannot be further extended
我知道这意味着任何类不能扩展类,因为它的final类。如果我删除extends Class<?>
,则方法constructMapType(...)将因类型而失败。 我的问题是我如何实现我的方法,所以我没有得到这个警告?
我认为我们的目标是有点不同,因为它不是关于构建'Map'实例,但创建'MapType',这是数据绑定所需的Jackson类型表示,让Jackson知道将数据绑定到(或有时来自)的类型的细节。 – StaxMan