简体   繁体   English

如何使用Eclipse为接口/抽象类中的所有未实现方法生成方法存根?

[英]How to generate the method stubs for all un-implemented methods in interfaces/abstract classes using eclipse?

In eclipse I have the following problem very often while writing java code: While coding (especially in the early time of coding) I often have to change interfaces until everything fits well. 在Eclipse中,我在编写Java代码时经常遇到以下问题:在编码时(尤其是在编码的早期),我经常不得不更改接口,直到一切都很好为止。 If I change such a Superclass I have to modify every single Subclass to implement the method. 如果更改此类超类,则必须修改每个子类以实现该方法。

This is clearly necessary to make the whole code run but I would like to test things without having to code every in a single bit. 这显然是使整个代码运行的必要条件,但我想进行测试而不必每次都编写代码。 Further the trick with 进一步的把戏

  • Opening the class 开课
  • Clicking on the (errorous) class name 单击(错误的)类名称
  • ressing <Alt> + <1> and selecting Implement all un-initialized methods 使用<Alt> + <1>并选择“ Implement all un-initialized methods

takes quite some time when I have to do it many times. 我必须花很多时间来做很多次。

Is there a way to select all related classes and click in the IDE on some magical menu to generate all non-implemneted methods in these classes as stubs? 有没有一种方法可以选择所有相关的类,然后在IDE中的一些魔术菜单上单击以在这些类中将所有未实现的方法生成为存根?

The problem is not IDE that do not provide the support for such action. 问题不在于IDE不提供对此类操作的支持。 But the way your coding looks, that needs to improve. 但是,您的编码方式需要改进。

An alternative for you may bring Java 8 where you can use the default methods implementation for interface. 您可以选择使用Java 8作为替代方法,在Java 8中可以使用接口的默认方法实现。

Then you will no longer have to update child classes. 然后,您将不再需要更新子类。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM