hi
from the K and B book
When the
compiler encounters a String literal, it checks the pool to see if an identical String
already exists. If a match is found, the reference to the new literal is directed to the
existing String, and no new String literal object is created. (The existing String simply
has an additional reference.)
does this mean that only those strings are checked which hava reference ? what about the lost objects which they dont have nay
reference pointing to them?
String s = new String("abc"); // creates two objects,
// and one reference variable
In this case, because we used the new keyword, Java will create a new String object
in normal (nonpool) memory, and s will refer to it. In addition, the literal "abc" will
be placed in the pool.
>> this is alittle bit confusing could somebody please clear it up for me? does this mean s refers to two objects? why do we need to create two objects ? so what happens to the object which is in normal (nonpool) memory when we want to alter the objec refered to by s ? will it be aaboned as well? at last isn't it redundancy?