user1021630
user1021630

Reputation: 19

Handling functionality of wrapper classes

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

Answers (2)

Jack Edmonds
Jack Edmonds

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

Reid Mac
Reid Mac

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

Related Questions