Campbell Ritchie wrote:In OP's question however a space was removed and a different object was returned.
Campbell Ritchie wrote:
To answer the actual question:- look at the JLS (=Java® Language Specification) for the definiton of compile‑time constants (officially called, “constant expressions”). You will see that method calls are not permitted in any of the expressions. It tells you that...But the second instance of "abc" isn't a constant expression, being created via a method call, its actual value is only known at runtime, and it isn't put into the String pool. If you want that == test to return true, try changing the second line to read,
Constant expressions of type String are always "interned" so as to share unique instances, using the method String.intern.