Inconvertible types; cannot cast 'int' to '
public static <K,V> Map<K, V> newMapT(V... objects) {
Map<K, V> map = new HashMap<>();
for (V object : objects) {
map.put((K)1, object);
}
return map;
}
解决方法:
map.put((K)new Integer(1), object);
这篇博客讲述了如何修复Java中尝试将整数1作为键值对插入到Map<K, V>时遇到的类型不匹配问题,提示读者正确使用强转或创建Integer对象进行转换。

1995

被折叠的 条评论
为什么被折叠?



