Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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()

like image 897
mwKART Avatar asked Mar 08 '17 10:03

mwKART


People also ask

How do you override the getter method in Lombok?

From Lombok documentation: You can always manually disable getter/setter generation for any field by using the special AccessLevel. NONE access level. This lets you override the behaviour of a @Getter, @Setter or @Data annotation on a class.

How do I exclude a field in Lombok getter?

To override the access level, annotate the field or class with an explicit @Setter and/or @Getter annotation. You can also use this annotation (by combining it with AccessLevel. NONE) to suppress generating a getter and/or setter altogether. Show activity on this post.

How do you set the setter and getter with Lombok?

Overview. You can annotate any field with @Getter and/or @Setter , to let lombok generate the default getter/setter automatically. A default getter simply returns the field, and is named getFoo if the field is called foo (or isFoo if the field's type is boolean ).


1 Answers

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.

like image 108
Daij-Djan Avatar answered Sep 20 '22 08:09

Daij-Djan