Is Java String really immutable?
java
Solution
Immutable means that, from an outside perspective, the value of the object cannot be changed.
If `hashCode` is being cached, the internal state of the object may be different after the first `hashCode` call. But that call is read-only, and you can't change the value of the object as it appears to the outside world.
In other words, it's still the same string.
Problem
In String source it looks like the hash code value (private int hashCode) is set only if the method public int hashCode() was called at least once. That means a different state. But will the hashCode be set in the following example: ``` String s = "ABC"; ? ``` Will ``` String s = "ABC"; s.hashCode(); ``` help with subsequent comparisons performance?