Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Intellij default getter/setter templates delete my boolean "is" variable name prefix?

I have an entity. I defined variable as boolean and I created Getter and Setter methods with Intellij Idea Shortcuts.

private Boolean isForLaboratory = false;

ddasd

enter image description here

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?

like image 589
Arif Acar Avatar asked Jun 14 '16 01:06

Arif Acar


1 Answers

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.

like image 64
vikingsteve Avatar answered Nov 04 '22 09:11

vikingsteve