wood burning stoves 2.0*
The moose likes Java in General and the fly likes immutable objects.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "immutable objects...." Watch "immutable objects...." New topic
Author

immutable objects....

prateek sharmaa
Ranch Hand

Joined: May 15, 2010
Posts: 38
hi all,
can anyone please tell me that what are immutable objects in Java other than the following :
(1) String
(2) Wrapper Objects

and how can we make objects immutable??
Istvan Kovacs
Ranch Hand

Joined: May 06, 2010
Posts: 100
http://java.sun.com/docs/books/tutorial/essential/concurrency/imstrat.html

(Under the hood, String isn't completely immutable, it's effectively immutable. The string's hash code is cached in an instance variable, but is not computed until it is first accessed.)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

prateek sharmaa wrote:and how can we make objects immutable??

Please SearchFirst. This question has been asked several times before.
prateek sharmaa
Ranch Hand

Joined: May 15, 2010
Posts: 38
thanks Rob and Istvan for the reply and i am really sorry for posting the question without searching.

now can you please give me the answer of my first question that whether any other objects are there other thatn Strings and Wrapper objects that are immutable??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

java.lang.Class
java.lang.Object
java.net.URI

And then I got bored

In essence, any class that does not allow its internal state (fields) to be changed is immutable. Any stateless object (like instances of java.lang.Object) are inherently immutable.
 
Don't get me started about those stupid light bulbs.
 
subject: immutable objects....
 
Similar Threads
Strange answers about "Strings" by JAMIE JAWORSKI
Confusion about string objects
HashMap keys
Immutable classes in java
Wrapper Classes