liveBook · Manning

Boxing

Boxing is the conversion of a value, typically a primitive or value type, into an object or reference representation, either explicitly or implicitly.

How 3 Manning books explain it

100 Java Mistakes and How to Avoid Them

A boxing conversion converts a Java primitive value to an object of its corresponding wrapper type, either explicitly or implicitly.

How it is used
Prevents failures and misleading behavior caused by implicit primitive-wrapper conversions in expressions, comparisons, tests, and collections.
How deep it goes
Explains implicit valueOf and primitive-value conversions through conditional-expression failures, caching behavior, and signed-zero consequences.
Examples
Uses a mixed Double/double conditional, cached Integers, a malformed JUnit assertion, and Double values for positive and negative zero.
What you can do after
Diagnose/debug with it by exposing implicit conversions, avoiding null unboxing, and replacing wrapper identity checks with content comparisons.

Read how 100 Java Mistakes and How to Avoid Them explains boxing →

Clojure: The Essential Reference

Autoboxing is the implicit conversion of primitive values to object representations and, where applicable, the reverse conversion.

How it is used
Explains surprising reference-identity results when Clojure compares primitive values through Object-based calls.
How deep it goes
Traces implicit boxing into generated Object arguments and contrasts it with constructors, cached valueOf calls, and variable bindings.
Examples
Uses 100 and 1000 Long values, def and let bindings, Long constructors, and Long/valueOf to expose identity differences.
What you can do after
Diagnose reference-identity surprises caused by boxing and choose value-based comparison when equivalence is intended.

Read how Clojure: The Essential Reference explains boxing →

Kotlin in Action, 2E

Boxing is the representation of a primitive value as an object instance such as java.lang.Integer.

How it is used
Explains how Kotlin array choices support Java interoperability and efficient primitive storage.
How deep it goes
Distinguishes boxed and primitive array representations, then stops short of broader boxing rules outside arrays.
Examples
Uses Array<Int>, IntArray, intArrayOf, and zero-filled primitive-array examples.
What you can do after
Apply it by selecting Array<Int> for object-array compatibility or IntArray for unboxed primitive storage.

Read how Kotlin in Action, 2E explains boxing →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.