Boxing (computer programming): Difference between revisions

Content deleted Content added
No edit summary
Line 1:
{{Cleanup|date=November 2006}}
In [[computer science]], an '''object type''' (a.k.a. wrapping object) is a [[datatype]] thatwhich is used in [[object-oriented programming]] to [[wrapper pattern|wrap]] a non-object type to make it look like an [[object (computer science)|object]].
 
Some [[object-oriented programming language]]s make a distinction between objects and non-objects, often referred to as [[primitive type]]s, for reasons such as runtime efficiency and syntax or semantic issues. For example, [[Java (programming language)|Java]] has [[primitive wrapper class]]es corresponding to each primitive type: <code>Integer</code> and <code>int</code>, <code>Character</code> and <code>char</code>, <code>Float</code> and <code>float</code>, etc. Languages like [[C++]] make little or no distinction between objects and non-objects; thus, the use of object type is of little interest.
Line 16:
For example J2SE 5.0 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.
 
===Unboxing===