在Android Studio中是否有一个自动生成给定类中的getter和setter的快捷方式?


当前回答

创建变量 右击 选择“生成”,然后选择“Getter和Setter”选项

其他回答

在编辑器中使用Alt+ Insert (Windows)或Command+ N (Mac),您可以轻松地为类的任何字段生成getter和setter方法。这与使用菜单栏->代码->生成…

然后使用shift或control按钮,选择所有你需要添加getter和setter的变量

另一种有趣的方式

在对象定义之后的任何地方输入参数名称,你会看到setter和getter,只需选择并单击enter:)

我尝试使用Android Studio 2.3

以防有人使用Eclipse

Windows 8.1操作系统| Eclipse Idle Luna

声明顶级变量私有字符串用户名Eclipse在屏幕左侧生成一个警告,单击该警告,会显示一些建议,然后选择generate。

在Mac上使用Ctrl+Enter来获得生成setter, getter,构造函数等选项列表

Android Studio和Windows:

FN + 选项 + 插入