2017-05-08 270 views
2

我的IDE给Integer提供了一个不必要的装箱警告。我在Netbeans中得到了不必要的装箱整数

// Custom 
double[] Cvalues = {18,1,0,0,17}; 
methodParams.put(Integer.valueOf(this.getCustom()), Cvalues); 
+3

为什么你需要这样的:'Integer.valueOf(this.getCustom())'?只需使用'getCustom()'。 –

+1

问题是什么?你只是告诉我们你的IDE告诉你,你正在做不必要的拳击。你认为你的IDE在骗你吗?实际上你在做不必要的拳击。 – Michael

+0

我的IDE抱怨缺少分号。咄! –

回答

3

如果你有一个Map<Integer, Object> myMap和你做这样的事情:因为与Integer类的包装

Map<Integer, Object> myMap = new HashMap<>(); 
myMap.put(Integer.valueOf(1), "A"); 
myMap.put(Integer.valueOf(10), "B"); 
myMap.put(Integer.valueOf(13), "C"); 

那么编译器会生成警告是没有必要的......

它将足以做到:

myMap.put(1, "A"); 
myMap.put(10, "B"); 
myMap.put(13, "C"); 

你的情况

methodParams.put(Integer.valueOf(this.getCustom()), Cvalues); 

看起来像getCustom()方法正在返回的整数原始使原始不必要的拳击/包装。

只是做:

methodParams.put(getCustom(), Cvalues); 
相关问题