7.6. Boxing and Unboxing

In the Java programming language, primitives and objects are not interchangeable. Although there are methods to convert a primitive to its wrapper object and vice versa, you cannot pass a primitive to a method whose signature expects the wrapper object and vice versa. For example, in the following method call, the age parameter literal must be an int primitive; similarly, the result of this method must be assigned to the wrapper object for int, which is

java.lang.Integer.
public Integer setAge(int age);

C# addresses this problem via boxing and unboxing, wherein the alias of the value type is interchangeable with its System namespace class. Boxing and unboxing enable value types to be treated as objects.

7.6.1. Boxing ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.