'Edit lombok getter method name for boolean member having prefix "has"

I am having a boolean variable hasObject in lombok which generates isHasObject(). I am using @Data lombok annotation. How can i change the method to hasObject()



Solution 1:[1]

in your case it could be:

 class XY : Object {
      @Getter(fluent = true)
      public boolean hasObject;
 }

OR

 @Accessors(fluent = true)
 class XY : Object {
      public boolean hasObject;
 }

according to the docs:

fluent - A boolean. If true, the getter for pepper is just pepper(), and the setter is pepper(T newValue). Furthermore, unless specified, chain defaults to true. Default: false.

Solution 2:[2]

Combining the Accessors and Getter, you might get the folllowing:

 class ExampleClass {
      @Accessors(fluent = true)
      @Getter
      private boolean hasObject;
 }

is an equivalent to the Vanilla Java:

class ExampleClass {
    
    private boolean hasObject;

    public hasObject() {
        return hasObject;
    }

Which is what you wanted, I guess.

Solution 3:[3]

Just like this:

 @Data
 class ExampleClass {
     
      private Object data;

      @Accessors(fluent = true)
      private boolean hasObject;
 }

This will provide getData() and hasObject() methods.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daij-Djan
Solution 2 Benjamin
Solution 3 Rami