Content deleted Content added
TakuyaMurata (talk | contribs) m →Boxing |
m →Boxing: - Capitalization, removed contractions, <code> around int |
||
Line 4:
==Boxing==
'''
For a more concrete example, in Java, a LinkedList can change its size, but an array must have a fixed size. You might desire to have a LinkedList of
To get around this, you can box your
===Autoboxing===
Autoboxing is the term for treating a primitive type as an object type without any extra code.
For example, as of Java 5.0, Java will now allow you to create a LinkedList of
This action is called autoboxing, because it is boxing that is done automatically (and implicitly) by the computer, instead of requiring you to do it yourself.
Line 20:
Unboxing is the term for treating an object type as a primitive type without any extra code.
For example, in versions of Java prior to 5.0, the following code
Integer i = new Integer(9);
Line 26:
Integer k = i + j;
The last step, in particular,
int i = 9;
Line 32:
int k = i + j;
As of Java 5.0, the first example is now treated just like the second example. The Integer is '''unboxed''' into an <code>int</code>, the two are added, and then the sum is '''autoboxed''' into a new Integer.
[[Category:Data types]]
|