Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
Eclipse 是一个很棒的 IDE!
... 或...
< img src="https://i.sstatic.net/3i7Wh.png" alt="在此处输入图像描述">
在 Netbeans 中...
Eclipse is an awesome IDE!
... or...
In Netbeans...
Eclipse 具有生成 getter 和 setter 的功能。
来源:生成吸气剂和设置器
Eclipse has the functionality of generate getters and setters.
Source: Generate Getters and Setters
eclipse 提供了这个。您也可以使用我的插件:https://stackoverflow.com/questions/2733311/复制字段和方法/2734647#2734647。
eclipse provides this. You can use my plugin as well : https://stackoverflow.com/questions/2733311/copy-field-and-methods/2734647#2734647.
这是 eclipse IDE 的标准功能(我想也是其他 IDE 的标准功能)。
快捷键:ALT+s -> r 显示 getter/setter 对话框(如果选择了包含类成员的类)
BTW - 为类成员自动生成 getter/setter 存根并不是重构。
自动生成这些存根不会重构(现有)代码。它会自动添加方法实现。而且,如果我们查看 Eclipse,我们在重构列表中找不到相应的操作(附加提示)。
进一步阅读:自封装字段
It's a standard feature of the eclipse IDE (and of other IDEs too, I suppose).
Shortcut: ALT+s -> r shows the getter/setter dialog (if a class with class members was selected)
BTW - autogenerating getter/setter stubs for class members is not a refactoring.
Autogenerating those stubs does not restructure the (existing) code. It automatically adds method implementations. And, if we look at eclipse, we don't find the according action in the list of refactorings (additional hint).
Further Reading: Self Encapsulate Field
根据您使用的 IDE,这是提供的标准功能。例如,在 Netbeans 中 - 右键单击您的 Java 类并选择 Refactor ->封装字段。您还可以选择访问器的可见性、出现顺序和插入点。
Depending on what IDE you use, this is a standard feature provided. For instance, in Netbeans - right click on your java class and choose Refactor -> Encapsulate Fields. You can additionally select the accessors visibility, order of appearance and insert point.