Strange auto-generated getter and setter in eclipse

When I use auto-generation for getter / setter in Eclipse for a class field called 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 that I use work with reflection and cause getter / setter using the name "get" + capitalized field name.

Can I change the code generation for getter / setter in eclipse to create output like getLAttr() and setLAttr() ?

+4
source share
3 answers

1) I do not think it is possible, a similar discussion:

Change Eclipse Getters Setter Syntax

2) another option, as an alternative, is to use patterns for getters and setters. although there is a small problem, a similar discussion:

How to deal with Camel Case for Eclipse templates?

+2
source

In eclipse, you can specify your own getter / setter names. Make your variable private. Go to the error where you are trying to access a private variable in another class. Choose a quick fix for getter / setter generation. A dialog box appears in which the names of the getters / setters can be changed.

+2
source

What version of Eclipse are you using? I tried this in Eclipse 3.5.2, and when I went over the field and clicked “create getter and setter for“ lAttr ”, the dialog that appeared allowed me to change the generated names, in this case from getlAttr to getlAttr and setlAttr to setlAttr . Another option is just specify your LAttr field from the start and avoid all the mess.

0
source

All Articles