In the Immutables documentation it says that:
For advanced use cases, it may be desirable to have builders that produce different types of objects but conform to the same interface, akin to the original Builder pattern. This is achievable by declaring a static nested class named “Builder” which will be extended by the generated builder.
It then provides an example where:
- there is an interface that multiple Immutable classes implement called Vehicle
- there is an interface for the builders the Immutable class will generate call VehicleBuilder
- the two abstract Immutable classes Scooter and Automobile implement Vehicle and have a abstract static class that implements VehicleBuilder.
This is super useful but it means every Immutable implementation needs to duplicate the abstract static class line. Is there any way to push this up into the parent definition?
I've tried making Vehicle an abstract class and moving the abstract static class into it:
public abstract class Vehicle {
public abstract static class Builder implements VehicleBuilder {}
}
However this does not work and the builder on the generated class does not extend it.