Sunday, 13 May 2018

java - How can you say String is immutable since you can change it?

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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...