简体   繁体   English

如何配置Eclipse在默认情况下而非私有创建受保护的Java方法?

[英]How do I configure Eclipse to create protected java methods by default instead of private?

When I use Eclipse 3.5 to auto-create methods for me (for example, by calling a method that does not yet exist, then using Quickfix to create the method), Eclipse creates the method with private scope. 当我使用Eclipse 3.5为我自动创建方法时(例如,通过调用尚不存在的方法,然后使用Quickfix创建方法),Eclipse将创建具有私有作用域的方法。

I'd like to change that so that it's created with protected scope by default. 我想更改它,以便默认情况下使用受保护的范围创建它。 How can I do so? 我该怎么办?

Already in 2002 在2002年

I've just discovered the Quick Fix feature in the F2 build. 我刚刚在F2版本中发现了快速修复功能。 It's really cool. 这真的很酷。
One question: Is there a way to change the way it creates methods for you? 一个问题:有没有办法改变它为您创建方法的方式? I would like the new methods to be protected instead of private. 我希望保护新方法,而不是私有方法。

there's no way to do this now. 现在无法执行此操作。
Please enter a feature request a. 请输入功能请求

Ouch. 哎哟。 And 7 years later, for the 3.5 edition, it does not seem to have changed one bit. 七年后的今天,对于3.5版,它似乎一点也没有改变。 In fact, other quick fixes produce incorrect private methods (in another context though, like bug 271551 ) 实际上,其他快速修复会产生不正确的私有方法(尽管在另一个上下文中,例如bug 271551

Arguably, in this instance, the generation of private method could be view as a "good practice", forcing the developer to explicitly raise the visibility level of said method (with the adequate javadoc saying why this method could be sub-classed or is even a public one) 可以说,在这种情况下,私有方法的生成可以被视为“良好实践”,从而迫使开发人员显式提高该方法的可见性级别(适当的javadoc指出了为什么可以将该方法子类化甚至是什至是)。一个公共的)

You might have a look at: Eclipse templates , but what you want to do, can only be done by changing the "private_method" template, if and only if that template is used by the fix suggestion logic, and I'm not sure that you can change that logic. 您可能会看一下: Eclipse模板 ,但是您想做的事情只能通过更改“ private_method”模板来完成,前提是并且仅当修订建议逻辑使用了该模板,并且我不确定您可以更改该逻辑。 Plus, if this would work, then the template would not represent the true meaning of having private methods... for all cases. 另外,如果这行得通,那么该模板将无法代表拥有私有方法的真正含义……在所有情况下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何配置Eclipse,以便在Java类的底部添加私有字段? - How to configure Eclipse so it adds private fields at the bottom of a Java class? 如何反射性地调用 Java 8 默认方法 - How do I invoke Java 8 default methods reflectively Eclipse + Java:如何从默认包中导入类? - Eclipse + Java: How do I import classes from the default package? 如何在Java中使用或创建私有类的变量 - How do I use or create a variable of a private class in Java 如何在 class 中创建私有 ArrayList? (爪哇) - How do I create a private ArrayList within a class? (Java) Java 访问修饰符关键字(私有、默认、受保护、公共或最终,static 等)自动隐藏在 eclipse 中,但显示在源文件中 - Java Access Modifiers keyword (private, default, protected, public or final, static etc..) automatically hide in eclipse but show in source file 如何在Eclipse中配置自动格式设置? - How do I configure autoformatting in Eclipse? 如何让子类使用父类的受保护方法? - How do I get a subclass to use a parent class' protected methods? Java接口:无法使已实现的方法受保护或私有 - Interfaces in Java: cannot make implemented methods protected or private Java阻止在类外调用私有或受保护的方法 - Java prevent calling private or protected methods outside of class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM