Can I have an abstract builder class in java with method chaining without doing unsafe operations?

后端 未结 3 2060
一个人的身影
一个人的身影 2021-01-31 18:08

I\'m trying to have an abstract base class for some builder classes so I can easily reuse code between the Builder implementations. I want my builders to support method chaining

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 18:52

    This should help:

    abstract class AbstractBuilder>
    {
       public AbstractBuilder foo()
       {
          // set some property
          return (AbstractBuilder) this;
       }
    
       abstract AbstractBuilder bar();
       abstract Object build();
    }
    

提交回复
热议问题