Reputation: 19
Although the Wrapper classes provide needed functionality, Java code is sometimes overly complicated due to the necessary conversions between the primitive and wrapper versions of data being manipulated. How can this be handled?
Upvotes: 0
Views: 102
Reputation: 33171
In Java, this is now handled automatically for you through a process known as Autoboxing.
Autoboxing occurs when the code requires a reference type but you have passed a primitive type. A common example is adding items to a collection.
LinkedList<Integer> myList=new LinkedList<Integer>();
int x = 3;
myList.add(x); //x is autoboxed from an int to an Integer.
Upvotes: 1
Reputation: 2489
I know I put it in the comments section, but this after reading your question again. This is the exact reason they created autoboxing --> Autoboxing
Upvotes: 1