java中修改private,自动将public更改为private(Java)

I am doing a refactoring on code is translated from other languages into Java and I want to do it automatically. My problem is that I have a lot of methods that aren't private but are just called in the same class that they are declared and I want to make them private. I have a lot of classes and I guess if there is something that can help me to do it semi-automatically I would like to know it.

Do you know if I can look for these methods to make them private fastly? I am using Eclipse.

解决方案

Replace all is one option.

But I suggest you don't do it. private and public are there for the programmer. If you only call a method from the class itself, it doesn't automatically mean it has to be private. The best thing you can do is go through them one at a time and ask yourself "should this method be part of the public interface or not?".

Personally, whenever I encounter a private method in a class which I need to use, 99% of the time I leave it private and look for a workaround. That's because I assume the original author of the code knew what he was doing. Of course, this doesn't always apply.

private is a statement of intent. It's like saying - if you need to use this from outside the class, you're doing something wrong. You shouldn't need this.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值