• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class Immutable

 
sreejith panampilly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can make a class Immutable?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very simply, don't provide any way to modify any of the member variables. It's that simple. Make sure they're all private, and preferably final, and don't change them after the constructor.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic