Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes How to make a Immutable Object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to make a Immutable Object?" Watch "How to make a Immutable Object?" New topic
Author

How to make a Immutable Object?

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
String is a immutable Object?
similarly Can we make an immutable Object in java ?

I have read that we can make a immutable Object without providing any setter methods ?? Is this true ?

If there are no setter methods on to our Object then how can we set data initially? Is this possible if i make the setter methods as final??


If you want something you never had do something which you had never done
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

This question has been discussed many times before, try searching this forum. I have found this and this for you .


SCJP, SCWCD.
|Asking Good Questions|
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
another useful link i found earlier:How to create Immutable class


<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to make a Immutable Object?
 
Similar Threads
How to make class immutable ?
immutale objects
immutable
Immutable classes
DTO - immutable vs mutable and accessors vs public variables