Hi,
In Chapter 3, p236 of K & B
SCJP 1.5 Certification Text has the following excerpt. Can you tell me how the JVM saves memory with this feature implementation? Thanks.
Produces the output:
different objects
meaningfully equal
This example produces the output:
same object
meaningfully equal
Yikes! The equals() method seems to be working, but what happened with ==
and != ? Why is != telling us that i1 and i2 are different objects, when == is saying
that i3 and i4 are the same object? In order to save memory, two instances of the
following wrapper objects will always be == when their primitive values are the same:
-- Boolean
-- Byte
-- Character from \u0000 to \u007f (7f is 127 in decimal)
-- Short and Integer from -128 to 127
From K & B SCJP Certification Text Errata, the following is abstracted:
236....clarify...Sentence before bullet points s/b: In order to save memory, two instances of the following wrapper objects, created through autoboxing, will always be equal...