It's up to the individual JVM whether to reuse strings or not;
The Java language requires that identical string literals (that is, literals that contain the same sequence of Unicode characters) must reference the same instance of class String.
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
Zelix KlassMaster's String Encryption technology encrypts your String literals where they are stored in the Constant Pools of your class files. It then adds fragments of code to your classes so that your Strings are decrypted at runtime.
"I'm not back." - Bill Harding, Twister
Originally posted by Max Habibi:
What I was getting to was that the JVM is free to return true or false for the following...
Originally posted by Ernest Friedman-Hill:
I don't want this to be "pile on Max" day, but this actually isn't true, either. Invoking new String() must result in the creation of a new, unique String object; I think JLS 15.9.3 is the authority for this, but there may be a stronger statement elsewhere.
Originally posted by Ernest Friedman-Hill:
Your link is to the first edition; I was looking at the second edition. Even so, you're right, I didn't mean 15.9.3 -- I meant 15.9.4! See
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#41147
SCJP 1.2, SCWCD, SCBCD
The nice thing about Standards is that there are so many to choose from!
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|