Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Autoboxing automatically wraps a value of a primitive type with the corresponding wrapper object. The Java Language Specification (JLS), §5.1.7, "Boxing Conversion" [JLS 20052015], explains which primitive values are memoized during autoboxing:

...

Note that Java Virtual Machine (JVM) implementations are allowed, but not required, to memoize additional values [JLS 20052015]:

Less memory-limited implementations could, for example, cache all characters and shorts, as well as integers and longs in the range of −32K to +32K. (§5.1.7)

Code that depends on implementation-defined behavior is nonportable. It is permissible to depend on implementation-specific ranges of memoized values provided that all targeted implementations support these greater ranges.

...

...