I have a class with lots of fields. They should basically be set at the constructor phase and never change. Semantically the class then is an immutable one.

public class A{
    final int a;
    final short b;
    final double e;
    final String f;
    final String g;
    //and more
}

The problem is that normally these fields have default values and therefore I do not want to always burden the user with a constructor with all of them. Most time, they just need to set a couple of them. There are a couple of ways to solve this:

  1. I would need lots of constructor with different signature.
  2. Create a bunch of set method of these field and only set those non-default value. But this somehow indicate a different semantics other than immutable nature.
  3. Create a new parameter class that is mutable and use that class as constructor.

None of that is totally satisfactory. Is there any other approach? Thanks. One way

Edit
Report