Compiler doesn't recognize Lombok Getter for overriden method

Viewed 5061

Assuming we have an interface TestInterface in an external artifact, that we cannot change:

public interface TestInterface {

    Boolean isTest();
    //more getter and setter methods
}

and an implementation of this interface, with more members corresponding to the parent interface. Lombok's generated getters/ setters are not recognized by the compiler, so I must add the actual getter method to make the following class compilable.

@Getter
@Setter
public class TestImplementation implements TestInterface {

    Boolean test;
    //more members
}

The compilation error is the standard error you get when a method of the interface is not implemented:

my.package.TestImplementation is not abstract and does not override abstract method isTest() in my.package.TestInterface

Supposing that Lombok's getters and setters are generated after compilation time, I don't understand why the normal call of getters (that are generated by Lombok) are compilable.

2 Answers

The problem seems to be that for a field Boolean test, Lombok will generate a method Boolean getTest(), instead of Boolean isTest() as required by the interface. Only if the property is boolean test then you get a boolean isTest() method, but then the return type does not match the interface.

So there seems to be no way around implementing the isTest method yourself.

Considering Java Bean Naming Conventions, the getter for your (wrapper object) field of type Boolean, should be getTest. Hence Lombok is doing "the right" thing. You could either change your field type to be of primitive boolean to get the desired method or adjust your interface to match the Java Bean Naming Convention.

Related