Some of the things I've learned every day since Oct 10, 2016
53: Boxing (Java)
December 2, 2016Posted by on
In the Java programming language, boxing refers to the conversion of a primitive value to some equivalent object wrapping that value, which allows the object containing the value to be passed by reference. (There are probably other benefits/motivations that I’m unaware of.) The conversion back to a primitive value is called unboxing. When boxing and unboxing are done automatically by the Java compiler, it is referred to as autoboxing.
A common example is the autoboxing between s (a primitive) and s (a class). For instance, when
is executed, there is no error, even though is an . The Java compiler autoboxes the into an equivalent object () and binds to that object.