I’m moving some old code to Lombok, and found some difference in the name of the generated getter methods in IDEA and Lombok.
For example, a field like:
private String aField;
In IDEA, a getter method will be generated like this (using IntelliJ Default template):
public String getaField() {
return aField;
}
But in Lombok, @Data will add a getter method named
getAField()
Which one is correct? It’s a bug or just a different choice?
I’m using IDEA 2023.1.5 community and Lombok 1.18.24.
Simon Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
What Intellij does (you can see it in Generate -> Getter -> ... in top right corner
):
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
That code is here: https://github.com/JetBrains/intellij-community/blob/2247153ca4c2073591785e1854e9a35f1b513010/platform/util/src/com/intellij/openapi/util/text/StringUtil.java#L981
So your case is basically the first thing that happens in that method:
if (s.length() > 1 && Character.isUpperCase(s.charAt(1))) return s;
Someone did it on purpose, that’s for sure, so a different choice, not a bug.
I don’t think it’s a bug.
I don’t think it should affect the business logic of the code, but
for me personally I would choose the getAField()
method, since in my opinion it’s more correct.
If you want, you can make a report to JetBrains, maybe they will comment on it.
Good luck with programming!