JVM Knowledge

Unboxing conversion converts expressions of reference type to corresponding expressions of primitive type. Specifically, the following eight conversions are called the unboxing conversions:

  • From type Boolean to type boolean
  • From type Byte to type byte
  • From type Short to type short
  • From type Character to type char
  • From type Integer to type int
  • From type Long to type long
  • From type Float to type float
  • From type Double to type double

At run time, unboxing conversion proceeds as follows:

  • If r is a reference of type Boolean, then unboxing conversion converts r into r.booleanValue()
  • If r is a reference of type Byte, then unboxing conversion converts r into r.byteValue()
  • If r is a reference of type Character, then unboxing conversion converts r into r.charValue()
  • If r is a reference of type Short, then unboxing conversion converts r into r.shortValue()
  • If r is a reference of type Integer, then unboxing conversion converts r into r.intValue()
  • If r is a reference of type Long, then unboxing conversion converts r into r.longValue()
  • If r is a reference of type Float, unboxing conversion converts r into r.floatValue()
  • If r is a reference of type Double, then unboxing conversion converts r into r.doubleValue()
  • If r is null, unboxing conversion throws a NullPointerException

A type is said to be convertible to a numeric type if it is a numeric type (§4.2), or it is a reference type that may be converted to a numeric type by unboxing conversion.

A type is said to be convertible to an integral type if it is an integral type, or it is a reference type that may be converted to an integral type by unboxing conversion.