Boxing (computer programming): Difference between revisions

Content deleted Content added
m robot Adding: nl:Boxing
No edit summary
Line 14:
Autoboxing is the term for treating a primitive type as an object type without any extra source code. The compiler automatically supplies the extra code needed to perform the [[type conversion]].
 
For example, as of J2SE 5.0, Java will now allow the programmer to create a <code>LinkedList</code> of <code>int</code>s. This does not contradict what was said above: the <code>LinkedList</code> still only lists objects, and it cannot list primitive types. But now, when Java expects an object but receives a primitive type, it immediately converts that primitive type to an object. Note that the declaration List<int> is illegal in Java, but List<Integer> is not, and autoboxing will allow adding of primitive ints to the collection
 
This action is called ''autoboxing'', because it is boxing that is done automatically and implicitly instead of requiring the programmer to do so manually.