Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Originally posted by Anupam Sinha:
Hi Veena
That's because b1.toString() method returns the value at runtime so it isn't in the pool
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Originally posted by Anupam Sinha:
Hi Veena
Think of it this way Veena. The value of b1.toString() is not available at compile time so it's not in the pool. The value is made available only at runtime so the value is not in the pool and hence the output false. To print a value there is no requirement that a String has to be in the pool. If you want you can put the value in the pool by using the intern() method. Though in case, if you replace Byte with String in the first line in the first post then the answer would be true. This is because the toString method of the String class returns itself.
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Don't get me started about those stupid light bulbs. |