Abdel Ramadan Abdel Ramadan - 9 months ago 83
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);

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download