Content deleted Content added
→Boxing: wording |
→Boxing: merge paras |
||
Line 7:
==Boxing==
Boxing is the process of placing a primitive type within an object so that the primitive can be used as a reference object. For example, [[List (computing)|lists]] may have certain [[Method (computer science)|methods]] which [[array data type|arrays]] might not, but the list might also require that all of its members be dynamic objects. In this case, the added functionality of the list might be unavailable to a simple array of numbers.
For a more concrete example, in Java, a {{Javadoc:SE|java/util|LinkedList}} can change its size, but an array must have a fixed size. One might desire to have a <code>LinkedList</code> of <code>int</code>s, but the <code>LinkedList</code> class only lists references to dynamic objects — it cannot list primitive types, which are value types.
To get around this, <code>int</code>s can be boxed into <code>Integer</code>s, which are dynamic objects, and then added to a <code>LinkedList</code> of <code>Integer</code>s. (Using [[generic programming|generic]] parametrized types introduced in [[Java Platform, Standard Edition|J2SE]] 5.0, this type is represented as <code>LinkedList<Integer></code>.)
On the other hand, [[C Sharp (programming language)|C#]] has no primitive wrapper classes, but allows boxing of any value type, returning a generic <code>Object</code> reference.
|