Skip to content
Advertisement

Lombok with SuperBuilder

I have a Java project that uses Lombok ( a java library that automatically plugs into the editor and build tools )

@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = { "id" })
@ToString(of = { "id" })
public class DacContexte {

    private Long id;
...
}

and this one:

@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class DacContexteReturn extends DacContexte {
}

but when I do the builder:

return  DacContexteReturn.builder()
                .id(5L)
                .build();

I got this error:

Required type: DacContexteReturn
Provided: DacContexte

Advertisement

Answer

Cannot reproduce.

> mkdir tmpDir
> cd tmpDir
> nano DacContexte.java

import lombok.*;
import lombok.experimental.*;

@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = { "id" })
@ToString(of = { "id" })
public class DacContexte {
    private Long id;
}

> nano DacContexteReturn.java

import lombok.*;
import lombok.experimental.*;

@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = { "id" })
@ToString(of = { "id" })
public class DacContexte extends DacContexteReturn {
    private Long foo;
}

> nano Test.java

class Test {
    void foo() {
        DacContexteReturn dcr = DacContexteReturn.builder().id(5L).build();
    }
}

> javac -cp ~/lombok.jar *.java
[ no errors or warnings ]

Check to make sure you’re on the latest lombok (currently, 1.18.16), and if that doesn’t solve the issue, check that you’ve accurately described the problem. If this error is occurring within eclipse or intellij, update the question.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement