Abdel Ramadan Abdel Ramadan - 2 months ago 15
Java Question

I get unnecessary boxing to Integer in Netbeans

My IDE gives a warning of unnecessary boxing to Integer.

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


If you have a Map<Integer, Object> myMap and you do something like:

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

then the compiler will generate warnings since the Wrapping with the Integer class is not necessary...

it will enough to do:

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

in your case

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

looks like getCustom() method is returning an integer primitive making the boxing/wrapping of the primitive unnecessary.

just do:

methodParams.put(getCustom(), Cvalues);