Wiki Markup |
---|
A Boxing conversion converts the values of a primitive type to the corresponding values of the reference type, for instance, from {{int}} to the type {{Integer}} \[[JLS 5.1.7 Boxing Conversion|http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.7]\]. It can be convenient in many cases where an object parameter is desired, such as with collection classes like {{Map}} and {{List}}. ItAnother use case is to pass object references to methods since primitive types always operate using pass by value. The resulting wrapper types also helpshelp avoidreduce clutter in code. |
Autoboxing can automatically wrap the primitive type to the corresponding wrapper object. But one must always be careful about this process, especially while performing comparisons. Section 5.1.7 of JLS 3rd Edition explains this point clearly:
...