有没有办法在 Eclipse 中自动生成 getter 和 setter?

有没有办法在 Eclipse 中自动生成 getter 和 setter?

问题描述:

我正在开发一个新的 Android 项目 (Java),并创建了一个包含大量变量的对象.由于我打算为所有这些添加 getter 和 setter,我想知道:Eclipse 中是否有快捷方式可以在给定的类中自动生成 getter 和 setter?

I am working on a new Android project (Java), and created an Object with a large number of variables. Since I am planning to add getters and setters for all of them, I was wondering: is there a shortcut in Eclipse for automatically generating the getters and setters in a given class?

在所需类的源代码窗口中调出上下文菜单(即右键单击).然后选择Source子菜单;从该菜单中选择 Generate Getters and Setters... 将出现一个向导窗口.

Bring up the context menu (i.e. right click) in the source code window of the desired class. Then select the Source submenu; from that menu selecting Generate Getters and Setters... will cause a wizard window to appear.

源代码 ->生成 Getter 和 Setter...

选择要为其创建 getter 和 setter 的变量,然后单击 OK.

Select the variables you wish to create getters and setters for and click OK.