You're not changing the contents of "Hello"
, you're changing the value of the variable s1
to refer to a different string object entirely.
Immutability has nothing to do with changing the value of the variable - if you want to prevent that, you can make the variable in question final.
No comments:
Post a Comment