【问题标题】:Eclipse Refactoring - Replace Java getters & setters with direct field accessEclipse Refactoring - 用直接字段访问替换 Java getter 和 setter
【发布时间】:2013-10-23 13:05:20
【问题描述】:

对于我们的纯数据类,我们不使用 getter 或 setter。在重构旧代码时,我希望能够通过直接字段访问快速替换(通常是 Eclipse 生成的)对 getter 和 setter 的调用。

有这样的插件吗?

注意我对封装的优缺点不感兴趣,这已经讨论了太多次了

所以,我想替换:

myData.setValue(17);
int value = myData.getValue();

与:

myData.value = 17;
int value = myData.value;

【问题讨论】:

    标签: java eclipse eclipse-plugin refactoring getter-setter


    【解决方案1】:

    您可以使用现有的内联方法重构。只需将有问题的字段公开,然后执行重构。如果您的代码库太大而无法手动执行此操作,您可以查看How to execute inline refactoring programmatically using JDT/LTK?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多