Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:12:29+00:00 2026-06-08T18:12:29+00:00

I read Effective Java, and there written If a class cannot be made immutable,

  • 0

I read Effective Java, and there written

If a class cannot be made immutable, limit its mutability as much as
possible…

and

…make every field final unless there is a compelling reason to make it
nonfinal.

So need I always make all my POJO(for example simple Bookclass with ID, Title and Author fields) classes immutable? And when I want to change state of my object(for example user change it in table where represented many Books), instead of setters use method like this:

public Book changeAuthor(String author) {
   return new Book(this.id, this.title, author);  //Book constructor is private
}

But I think is really not a good idea..

Please, explain me when to make a class immutable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:12:31+00:00Added an answer on June 8, 2026 at 6:12 pm

    No, you don’t need always to make your POJO immutable. Like you said, sometimes it can be a bad idea. If you object has attributes that will change over the time, a setter is the most comfortable way to do it.

    But you should consider to make your object immutable. It will help you to find errors, to program more clearly and to deal with concurrency.

    But I think you quoting say everything:

    If a class cannot be made immutable, limit its mutability as much as
    possible…

    and

    …make every field final unless there is a compelling reason to make
    it nonfinal.

    That’s what you should do. Unless it’s not possible, because you have a setter. But then be aware of concurrency.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read Effective Java by Joshua Bloch and removed the 'Constant Interface anti-pattern' from
It was suggested that Effective Java is a great book to read before programming
I'm trying out Effective Java book and enjoying it. I read Builder pattern and
I read from Effective Java that In the absence of synchronization the following sequence
I read Tom Kyte's Effective Oracle by Design. There he says to write most
I read Effective Java book and don't understand one paragraph where explained Clonable interface.
I am reading about double check locking from Effective Java . The code does
I need to write a program in Java which will read a relatively large
I've read through the Effective Go and Go Tutorials as well as some source,
I read about this from Effective c++ ,this is Col.10. It say it's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.