Map<String, Object> map = new HashMap<>();
map.put("score", 10);
BigDecimal score = (BigDecimal) map.get("score");
System.out.println(score);
取值直接强转报错
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
正确的处理办法
BigDecimal score2 = new BigDecimal((Integer) map.get("score"));
System.out.println(score2);
后记:map中的Long类型转Integer处理办法
Integer aaa = ((Long) map.get("aaa")).intValue();
如果是double类型处理:
BigDecimal score = BigDecimal.valueOf((Double) paramMap.get("score"));