Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make a class immutable  RSS feed

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

Can you please answer the two questions?

1) How do I make a class immutable?
2) How I synchronize a map?

Thanks
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Padma priya Gururajan wrote:1) How do I make a class immutable?



You can probably find quite a few discussions on this if you search. But here's an alternative way of looking at it. How do you make a class mutable? After all, there's no mutable state in the Object class, so adding mutability is something you do to a class. Then you need to not do that.
 
Marshal
Posts: 58421
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Padma priya Gururajan wrote: . . . 2) How I synchronize a map?

Thanks

If you look in the documentation for HashMap, it tells you what to do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!