自动将public更改为private(Java) [英] Automatically change public to private (Java)
问题描述
我正在重构代码,从其他语言翻译成Java,我想自动执行。我的问题是,我有很多不是私有的方法,但是在同一个类中被调用,它们被声明,我想使它们变为私有的。我有很多课,我猜,如果有什么可以帮助我半自动地做,我想知道。
你知道我是否可以寻找这些方法让他们快速私人吗?我正在使用Eclipse。
替换全部是一个选项。
但我建议您不要这样做。 private
和 public
是程序员。如果您只从类本身调用方法,它不会自动意味着 为 private
。你可以做的最好的事情是一次通过他们,问自己这个方法是公共接口的一部分还是不是?。
个人,每当我遇到一个我需要使用的类中的
private
方法,99%的时间我离开它 private
并寻找解决方法。这是因为我认为代码的原始作者知道他在做什么。当然,这并不总是适用。 private
是意向声明。这就像说 - 如果你需要从课外使用这个,你做错了。你不应该需要这个。
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.
这篇关于自动将public更改为private(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!