Home > Software design >  How can I customize lombok SuperBuilder's build method?
How can I customize lombok SuperBuilder's build method?

Time:10-31

I want to execute some method after lombok builder().build();.

But I don't want to execute it manually like builder().build().someMethod();

@SuperBuilder's build() was different from @Builder.

How can I customize it?

@SuperBuilder(buildMethodName = "defaultBuild")
class Foo {
    
    ...

    public static class FooBuilder {
        public FooBuilder build() {
            return defaultBuild().someMethod();
        }
    }
}

It works in @Builder but not in @SuperBuilder.

CodePudding user response:

Due to the cavalcade of generics and other trickery to make @SuperBuilder work, you can't just write it yourself. @SuperBuilder is more picky, in other words (@Builder will let you write various things yourself, SuperBuilder does not). For example, your FooBuilder class needs a bevy of generics. Instead of forcing you to read a lot of documentation, or delomboking to know what it should look like, SuperBuilder just doesn't let you, instead.

  • Related