I’ve got a question but to get an answer the following fact has first to be accepted: in some cases, Java Strings can be modified.
This has been demonstrated in the Artima article titled: “hi there”.equals(“cheers !”) == true
Link: http://www.artima.com/weblogs/viewpost.jsp?thread=4864
It still works nicely in Java 1.6 and it surely goes somehow against the popular belief that consists in repeating “Java Strings are always immutable”.
So my question is simple: can String always be modified like this and are there any JVM security settings that can be turned on to prevent this?
You need to add a SecurityManager. This site has an example and explanation:
Run with:
And the code: