1
@Data
public class show{
    @Transient
    private boolean value;
}

show ob = new show();

ob.getValue() //throws an error
ob.isValue() //runs smoothly

Why is this happening? Instead of boolean, if I use Boolean, I am able to get variable's value. Why am I not able to fetch value if I use primitive datatypes?

  • Does this answer your question? [Lombok annotation @Getter for boolean field](https://stackoverflow.com/questions/42619986/lombok-annotation-getter-for-boolean-field) – Eklavya Jun 24 '20 at 04:59
  • Here you find details https://www.baeldung.com/lombok-getter-boolean and how to customize it https://stackoverflow.com/questions/18139678/lombok-how-to-customise-getter-for-boolean-object-field – Eklavya Jun 24 '20 at 05:00

2 Answers2

1

Lombok's default behavior is to expose boolean Java methods with the prefix isXXX(), instead of using the getXXX() naming scheme. What you are seeing is just standard behavior.

If you want to override to Lombok's default isXXX() naming scheme, you may provide your own getter:

@Getter(AccessLevel.NONE)     // turn off Lombok here
private boolean value;

public boolean getValue() {
    return value;
}
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

When using Lambok, the default getter and setter used for type boolean are isValue() and setValue(boolean value) respectively. Whereas for type Boolean the getter and setter used are getValue() setValue(Boolean value).

Disable Lombok for the fields you don't want by sticking @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) on top of the field and write your own getters and setters

Zishan Khan
  • 167
  • 6