I have an entity. I defined variable as boolean and I created Getter and Setter methods with Intellij Idea Shortcuts.
private Boolean isForLaboratory = false;
After creation it generated this:
public Boolean getForLaboratory() {
return isForLaboratory;
}
public void setForLaboratory(Boolean forLaboratory) {
isForLaboratory = forLaboratory;
}
I expected getIsForLaboratory and setIsForLaboratory. Is it general convention for Java? Why Intellij deleted my prefixes?
If you pop up the Dialog to Generate
the Getter and Setter
, you can see:
Getter template: IntelliJ Default
Setter template: IntelliJ Default
Click on the button to the right of Getter Template
labelled with ...
and you can see the template code includes the following:
#if ($StringUtil.startsWithIgnoreCase($name, 'is'))
#set($name = $StringUtil.decapitalize($name))
#else
is##
In other words there is special handling for fields starting with is
- and if you want to write your own template, you can of course do this :)
As for why - there is a javabeans standard for boolean fields where the getter for a field named (for example) boolean enabled
can be isEnabled()
instead of getEnabled()
, and it's surely related to this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With