Lombok annotation @Getter for boolean field

Nitesh Kumar :

I am using Java lombok annotation @Getter to generate getters for my POJO. I have a 'boolean' field by the name 'isAbc'. The @Getter annotation in this case generates a method by the name 'isAbc()'. Shouldn't it generate a method by the name 'isIsAbc()'?

Harald Gliebe :

Read the 'small print' section on the lombok page https://projectlombok.org/features/GetterSetter.html

For boolean fields that start with is immediately followed by a title-case letter, nothing is prefixed to generate the getter name.

So the behavior you experience is as specified.

Note that the behavior is different for boolean and Boolean:

@Getter
private boolean isGood; // => isGood()

@Getter
private boolean good; // => isGood()

@Getter
private Boolean isGood; // => getIsGood()

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=420792&siteId=1