Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I customize lombok SuperBuilder's build method?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading