• Post Reply Bookmark Topic Watch Topic
  • New Topic

testing String as immutable

 
Mike Cunningham
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5388
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mean ??
 
WiLL Tao
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
No, tomorrow we rule the world! With this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!