Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Can't override method build when 2 class also have @SuperBuilder() #3438

Open
hoangdangduy opened this issue Jun 20, 2023 · 3 comments

Comments

@hoangdangduy
Copy link

Hi, Lombok team and people.

I use @SuperBuilder() in 2 class, I want override method build() of class child builder but it appear error "Abstract method 'build()' cannot be accessed directly" in super.build() in ClassChild

Version Lombok: 1.18.28
Version java: 17

ClassChild.java

@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class ClassChild extends ClassParent {
    private int age;

    public static ClassChildBuilder builder() {
        return new BuilderCustom();
    }

    public static class BuilderCustom extends ClassChildBuilder {

        public ClassChild build() {
            ClassChild classChild = super.build();
            return classChild;
        }

        @Override
        protected ClassChildBuilder self() {
            return this;
        }
    }
}

ClassParent.java

@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ClassParent {
    private String name;
}

Main class

ClassChild classChild = ClassChild.builder().name("Tom").age(20).build();

How should I fix to override the build() method success?

@janrieke
Copy link
Contributor

janrieke commented Jun 20, 2023

What are you trying to do?

Manually implementing any of @SuperBuilder's code is tricky and you should really know what you are doing.
At least start with the delombok'ed code. Otherwise you'll be totally lost without the exact type parameters.

BTW: This is not a bug, this is a usage question better asked at StackOverflow.

@hoangdangduy
Copy link
Author

What are you trying to do?

Manually implementing any of @SuperBuilder's code is tricky and you should really know what you are doing. At least start with the delombok'ed code. Otherwise you'll be totally lost without the exact type parameters.

BTW: This is not a bug, this is a usage question better asked at StackOverflow.

I want override to process continue logic in build(), it will auto check, client don't need care about it when create object by builder.

@janrieke
Copy link
Contributor

janrieke commented Jul 7, 2023

See https://stackoverflow.com/questions/61658719/customize-lombok-super-builder if you want to know how to implement a custom build method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants