aspose file tools*
The moose likes Java in General and the fly likes immutable object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "immutable object" Watch "immutable object" New topic
Author

immutable object

Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
hi all,
is it possible to make an Object immutable ?? for eg. consider an Object
Object obj = something();
if i call obj.toString() does it make this object immutable ?? becoz toString() returns String and String is immutable right ?? Plz guide me if im wrong..
is there any other way to make an Object immutable ??
thanks,
raj


SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Susilo Saja
Ranch Hand

Joined: May 27, 2003
Posts: 91
Hi Rajeev,
I only have little understanding about your question, hope this help.
Immutable object is object that can't be modified. You can achieve this by making all fields private and make no method that can modify the fields. The fields is only set during the creation of the object.
Susilo
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I wrote an article on Mutable and Immutable objects for the April newsletter. You could start there
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: immutable object