• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

immutable objects....

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 135
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


Please SearchFirst. This question has been asked several times before.
 
prateek sharmaa
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic