Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Piet Souris

When should I make a class immutable? - conflict with Effective Java book

Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone. Some time ago I started reading Effective Java book and some of its items put more doubts on me than before I had. This is the case of Item 17 that says: "Classes should be immutable unless there’s a very good reason to make them mutable.". It's crazy for me because in my daily work I've never tend to use immutables over mutables and I've never seen before this practice in the codes I've worked with. For example, if I should deal with an entity User class that is populated by Hibernate annotations I don't make it immutable or in case or creating a service class, the same.
Rather my idea about immutables is that you can use them for such classes like a utility class or objects that don't use to change.

I'd like to know your point of view to know how much this book is right.

Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic