I am wondering why eclipse produces the following getter and setter if i used the following boolean:
boolean isLifeTimeMember
The getter should be isIsLifeTimeMember() and not isLifeTimeMember()
I think it affected calling the variable isLifeTimeMember in JSP. because it will look at JSP and map it to isIsLifeTimeMember() getter method.
Error will result because there is no isIsLifeTimeMember() method but the getter generated by eclipse is isLifeTimeMember()
Thank you.
Eclipse name generation rules are that boolean getters should start with is
. If the variable name already starts with is
, then it thinks that no additional prefix is necessary.
Eclipse has a setting that controls the use of is
for generated boolean getters. Open up Preferences and navigate to Java > Code Style
. There you can uncheck the option "Use 'is' prefix for getters that return boolean". Eclipse-generated boolean getters will then start with "get", just like all the others.
Java has no problem, by the way, in having a field and a method with the same name.
However, having property names that start with "is" will probably cause problems with jsp. As described in this thread, it's better to avoid property names that read like questions (isLifeTimeMember) and instead just use the property itself as the property name (lifeTimeMember).
Code Example:
boolean lifeTimeMember;
public boolean isLifeTimeMember() {
return lifeTimeMember;
}
public void setLifeTimeMember(boolean lifeTimeMember) {
this.lifeTimeMember = lifeTimeMember;
}
And in JSP if you need to use this variable simply use variable name "lifeTimeMember".
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