What is the appropriate way to handle warning: "The expression of type x is boxed into x"

bn. picture bn. · Apr 27, 2014 · Viewed 11.9k times · Source

I'm not looking to to turn off or ignore the warning as in The expression of type x is boxed into X?.

I'd like to know what the correct way to handle/avoid this warning is if one was so inclined.

Answer

Jeffrey picture Jeffrey · Apr 27, 2014

Boxing and unboxing are operations you can do by hand, but they're build into the language to avoid the repetition you will undoubtedly encounter.

Integer obj = Integer.valueOf(5); // instead of Integer obj = 5;
int i = obj.intValue(); // instead of int i = obj;

In my opinion, the appropriate way to handle that warning to turn it off. But if that is not an option, you can do the above.