无法将json或map中的java.lang.Integer强制转换为java.lang.Double

1   HashMap<String,Object> myMap = new HashMap<>();
2   myMap.put("DoubleKey", 1);
3   myMap.put("AnotherDoubleKey", new Double(1));
4   Double getMyDoubleValue = (double) myMap.get("DoubleKey"); // This doesnt work. 
5   Double anotherDoubleKey = (Double) myMap.get("AnotherDoubleKey");
6   System.out.println(anotherDoubleKey);

如何使4号线正常工作?我在json中面临这个问题。

评论