• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mutable or Immutable. How to find?

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please tell me how to find whether a class is mutable or immutable.
Thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not any special property of the language -- i.e., there's no "immutable" keyword. The only thing you can do is to read the Javadoc for the class and see what it says.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ransika,
Why are you trying to figure this out? What problem are you trying to solve?
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please tell me how to find whether a class is mutable or immutable.
If there is no way to set the member variables of the class (typically by calling the setXXX() methods) except in the constructor, the objects of that class are immutable.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite true. See the article in the JavaRanch April Newsletter
Mutable and Immutable Objects
Dave
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite true. See the article in the JavaRanch April Newsletter
Mutable and Immutable Objects

Point well taken. Of course, I didn't mentioned the fact that the object can be mutated indirectly by manipulating the reference to its internal mutable fileds. Nice article, David!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic