How to ensure that builder pattern is completed?

后端 未结 7 1756
鱼传尺愫
鱼传尺愫 2021-02-05 13:38

EDIT: I am not worried about being called in the wrong order since this is enforced through using multiple interfaces, I am just worried about the terminal method getting called

7条回答
  •  轮回少年
    2021-02-05 14:17

    There is now an annotation processing based compiler plugin, that will check that for you, and throw compilation error, if the method is not present: Fluent API sentence end check.

    You can either annotate your final method with @End annotation, or if you do not control the class, you can still provide a text file with fully qualified method name(s), and get the check working.

    Then Maven can check during compilation.

    It only works in Java 8, upwards, because it uses new compiler plugin mechanism, introduced there.

提交回复
热议问题