首页 > 学院 > 开发设计 > 正文

Eclipse为成员变量设置前缀

2019-11-14 21:10:35
字体:
来源:转载
供稿:网友
Eclipse为成员变量设置前缀

Eclipse可以自动生成getter和setter,constructor。

菜单 - Source,

有Generate Getters and Setter,Generate Constructor using Fields,

只要勾选上,点击OK,就能生成对应的代码。还可以添加一些注释。

但是java的成员变量一般使用m作为开头,比如mText,这样生成的getter和setter就变成了

public String getmText() {return mText;}public void setmText(String mText) {this.mText = mText;}

有代码洁癖的人一定会一个一个的把不该有的 'm' 删掉。

其实Eclipse可以为成员变量设置一个前缀

打开PReferences,搜索框输入prefix

选择Java - Code Style

编辑Fields,Prefix list : 输入 'm'。

点击确定,这样生成的代码就会自动忽略前缀。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表