Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ImBase {
- protected ImBase(Builder b) {
- }
- public static class Builder<B extends Builder> {
- protected final BuilderHolder<B> holder;
- public Builder() {
- this.holder = new BuilderHolder(this);
- }
- public B setFoo(String value) {
- return holder.b;
- }
- public B setBar(int value) {
- return holder.b;
- }
- public ImBase build() {
- return new ImBase(holder.b);
- }
- protected static class BuilderHolder<T extends Builder> {
- public final T b;
- private BuilderHolder(T b) {
- this.b = b;
- }
- }
- }
- }
- public class ImBaseChild extends ImBase {
- protected ImBaseChild(Builder b) {
- super(b);
- }
- public static class Builder extends ImBase.Builder<Builder> {
- public Builder setGer(double value) {
- return holder.b;
- }
- @Override
- public ImBaseChild build() {
- return new ImBaseChild(this);
- }
- }
- }
- public class ImMain {
- public static void main(String[] args) {
- ImBase imBase = new ImBase.Builder().setBar(1).setFoo("22").build();
- ImBaseChild imBaseChild1 = new ImBaseChild.Builder().setGer(3.3).setBar(1).setFoo("22").build();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement