How to use Lombok @SuperBuilder with customized builder and several classes in hierarchy of heritance?

Viewed 311

I have such classes hierarchy:

@Data
@SuperBuilder
public abstract class Parent1 {
    Long id;
}
@Data
@SuperBuilder
public abstract class Parent2 extends Parent1 {
    String name;

    // Customized Lombok's builder
    public abstract static class Parent2Builder<C extends Parent2, B extends Parent2Builder<C, B>> {...}
}
@Data
@SuperBuilder
public class Child extends Parent2 {
    //some fields and methods
}

All worked fine when Parent1 and Parent2 were as one class (Parent with 2 fields) with Lombok's customized builder. But I had to separate one class in two different and got the next error while compiling: Parent2.java: error: method does not override or implement a method from a supertype @SuperBuilder

I have no idea which method I didn't implement.

P.S. I also have the same classes hierarchy (but without customized builder) in another package and there were no errors at all.

1 Answers

Right now, Parent2.Parent2Builder does no longer extends Parent1.Parent1Builder. If we change

public abstract static class Parent2Builder
        <C extends Parent2, B extends Parent2Builder<C, B>> {
    ...
}

to

public abstract static class Parent2Builder
        <C extends Parent2, B extends Parent2Builder<C, B>> 
        extends Parent1.Parent1Builder<C, B> {
    ...
}

It works as expected.

Related