Suppose I have the following class that is trying to be immutable
public class Computation { private final Operation operation; private final double epsilon; public Computation(Operation operation) { this.operation = operation;
And, for the sake of the question, let's say that I do not want to use the builder for this class (to solve the problem).
So the question is:
Is there a way to achieve this behavior without removing the final modifier in epsilon and preserving the two constructors?
That is, without doing something like
public class Computation { private final Operation operation; private final double epsilon; public Computation(Operation operation Double epsilon) { this(operation); this.epsilon = (epsilon == null) ? 0.01 : epsilon; } }
and without using a builder
public class Computation { private final Operation operation; private final double epsilon; private Computation(Builder builder) { this.operation = builder.operation; this.epsilon = builder.epsilon; } public static class Builder { private final Operation operation;
Lombo source share