About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Boxing

One of the core design choices made for .NET’s type system is to have a unified view over value types and reference types. By doing so, every type derives from the mother of all types: System.Object. Especially in the pregenerics era, this had several advantages because you could define a general-purpose data structure such as a list to hold objects of any type:

public class ArrayList{    private object[] items;    ...}

In languages such as Java, there was no such unification, requiring users to jump through seemingly artificial hoops to package up (the equivalent to) a value typed object in some “box” before it could be used where an Object-typed instance is expected:

// How things would look in Java, requiring ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required