Reputation: 16602
When I use the auto generation for getter/setter in Eclipse for an class field with a name like
String lAttr
it will produce this:
public String getlAttr() {
return lAttr;
}
public void setlAttr(String lAttr) {
this.lAttr = lAttr;
}
The first letter of the field will not be capitalized! But some frameworks which I use, work with reflection and invoke the getter/setter by using the "get" + capitalized field name.
Can I change the code generation for getter/setter in eclipse to produce an output like getLAttr()
and setLAttr()
?
Upvotes: 5
Views: 3007
Reputation: 21
It is possible to give your own names of getter/setter in eclipse. Make your variable private. Go to error where you are trying to access private variable in another class. Select the quick fix of generating getter/setter. It pops up a dialog where getter/setter names are modifiable.
Upvotes: 2
Reputation: 1670
1) I don't think it's possible, similar discussion:
Change Eclipse Getters Setters syntax
2) another option, as alternative, is to use templates for getters and setters. though there is a small problem there too, similar discussion:
How to deal with Camel Case for Eclipse Templates?
Upvotes: 2
Reputation: 1033
What version of Eclipse are you using? I tried this in Eclipse 3.5.2, and when I moused-over the field and clicked "create getter and setter for 'lAttr'", the dialog box that appeared allowed me to change the generated names, in this case from getlAttr
to getLAttr
and setlAttr
to setLAttr
. Another option would be to just name your field LAttr
from the start and avoid the whole mess.
Upvotes: 0