Unboxing conversion treats expressions of a reference type as expressions of a corresponding primitive type. Specifically, the following eight conversions are called the unboxing conversions:
- From type
Booleanto typeboolean - From type
Byteto typebyte - From type
Shortto typeshort - From type
Characterto typechar - From type
Integerto typeint - From type
Longto typelong - From type
Floatto typefloat - From type
Doubleto typedouble
At run time, unboxing conversion proceeds as follows:
- If
ris a reference of typeBoolean, then unboxing conversion convertsrintor.booleanValue() - If
ris a reference of typeByte, then unboxing conversion convertsrintor.byteValue() - If
ris a reference of typeCharacter, then unboxing conversion convertsrintor.charValue() - If
ris a reference of typeShort, then unboxing conversion convertsrintor.shortValue() - If
ris a reference of typeInteger, then unboxing conversion convertsrintor.intValue() - If
ris a reference of typeLong, then unboxing conversion convertsrintor.longValue() - If
ris a reference of typeFloat, unboxing conversion convertsrintor.floatValue() - If
ris a reference of typeDouble, then unboxing conversion convertsrintor.doubleValue() - If
risnull, unboxing conversion throws aNullPointerException
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.