File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes testing String as immutable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "testing String as immutable" Watch "testing String as immutable" New topic

testing String as immutable

Mike Cunningham
Ranch Hand

Joined: Nov 14, 2000
Posts: 130
Is there a way to test that a String is immutable by attempting to change the actual string object in the constant pool?
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5382
mean ??

"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
WiLL Tao
Ranch Hand

Joined: Dec 14, 2001
Posts: 56
Is this code ok?
because "==" is shallow compare,so if string is mutable, the refence address will not be changed.
but this code provdes m1 create new ojbect.

Thank Folks who <b>Make Sense</b> here.<br />SCJP Platform 2
I agree. Here's the link:
subject: testing String as immutable
It's not a secret anymore!