Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can we make an user defined object as immutable?  RSS feed

 
Rajan Venkat
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Would like to know "How to make an user defined object as immutable" like String object.

please note : Here i am not talking abt the final reference variable, saying all about Final object.
please let me know .

regards
Raj
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please reserve this forum for advanced Java questions.

I have moved this post to a more appropriate forum.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just write your class so that the state is only initialized in the constructor - don't provide any methods that modify the state of the object (i.e., no setter methods etc.).
 
Rajan Venkat
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jesper,

Thank you very much.

with regards,
Raj
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!