简体   繁体   中英

How to generate interface's methods into all implementation classes?

I am looking for some kind of refactoring feature in Eclipse to generate methods in implementation classes from an interface class. Let's say I have JavaClassImpl1 and JavaClassImpl2 , which implement JavaClassInterface . What I'd like to do is when I add a method to JavaClassInterface , the refactoring option is to generate empty methods in all implementation classes, in this case, in JavaClassImpl1 and JavaClassImpl2 .

If you haven't implemented all of the required methods in eclipse, it will show a bunch of compile-time errors in your class (the class will have a red underline).

If you hover over the class name, a pop-up will appear with available quick fixes, one of which will be Add unimplemented methods . If you select that eclipse will generate a stub for each unimplemented method.

Another way to access the same function is to rightclick in your class and select Source -> Override/Implement Methods... which will pop up a wizard which allows you to select which methods you would like eclipse to stub out for you.


Update

If the change you make to your interface is done via one of the eclipse refactor tools, then eclipse will generally update references to the thing that was changed. For instance, if you do a Refactor -> Introduce Parameter Object... on a method in your interface, then eclipse will automatically update implementing methods.

If you're adding code manually, eclipse doesn't even know about the change until the next time you compile, and you'll have to explicitly ask eclipse to refactor the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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