And also, since s1 == s4 is false, does not mean that strings created using the new keywork are not placed in the pool?
Scotty Mitchell wrote:The + operator has higher precendence than the ==. Effectively, the concatenation is occuring before the == hence they are not pointing to the same references. You are creating a new string object "2: hello" and seeing its its equal to the reference "hello", obviously this is false. If you were to put parenthesis around (s1==s2) you would get true I'm pretty sure?
You should know this you read the precedence post from the other daythis is why you need to know precedences.
And also, since s1 == s4 is false, does not mean that strings created using the new keywork are not placed in the pool?
If you use any constructor of string, the object will be created in the heap, and not find a reference in the string literal pool I'm pretty sure.
I actually thought that since one of the elements in the expression is a string, the + operator will be used for concatenating.
Scotty Mitchell wrote:And btw Strings are Immutable regardless of how they are created. Only StringBuilder and StringBuffer are mutable string objects.
The object reffered to by the reference variable "two" was created using the new keyword. As it is not refered to from the constant pool, what provides its immutability?
OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |