Posts Tagged ‘constructor’
Creating new instances of immutable primitive type wrappers (such as
Number subclasses and
Booleans) wastes the memory and time needed for allocating new objects. Static
valueOf() method works much faster than a constructor and saves the memory, as it caches frequently used instances.
It is guaranteed that two
Boolean instances and
Integers between -128 and 127 to be pre-cached, thus you definitely should not use the constructor to instantiate them.