If @Builder took as an argument another, unannotated class, and meant that all setX methods would be updated to return this, it would be a extension of the Decorator pattern. You could write:
class SomeExistingClassInALibrary {
SomeExistingClassInALibrary(int z);
int getX();
void setX(int x);
void someOtherMethod();
}
@Decorator(SomeExistingClassInALibrary.class, builder=true)
class MyIncrediblyUsefulNewClass {
}
would generate
class MyIncrediblyUsefulNewClass {
private final inner;
MyIncrediblyUsefulNewClass(int z) {
inner = new SomeExistingClassInALibrary(z);
}
int getX() { return inner.getX(); }
MyIncrediblyUsefulNewClass setX(int x) {
inner.setX(x); return this;
}
void someOtherMethod() {
inner.someOtherMethod();
}
}
If builder were *false*, the new class would implement all the interfaces the old one did, but wouldn't have the cool chainable semantics. With builder set to "true" it can only implement the interfaces that lack any setters.
M.