Intellij Idea How to add an interface implementation to classes?

For example, I have many classes than the implementation of my interface. After adding a new method definition to the interface, how can I quickly add empty interface implementations for all of these classes?

+8
editor intellij-idea code-completion automated-refactoring
source share
4 answers

Alt + Enter in the new interface method, Implementation method :

enter image description here

Press Enter , a list of implementation classes is displayed, select the desired classes using the Shift + keys or press Ctrl + A to select all of them, and then press Enter again to confirm your choice. Stub implementations will be added for all selected classes.

+23
source share

I think the best you can do is their tutorial in particular using

Ctrl + O

in the implementation class. Otherwise, I do not know how to create an entire class.

+5
source share

You can create an implementation of an interface by moving the carriage to the name of the interface and pressing option + return (on Mac) or ALT + Enter (on PC), then hover over the Implement interface and pressing return / Enter :

Use interface Please note that my carriage is not visible, but it is between h and a from Shape

Then IntelliJ will offer you the class name and which methods to include in the implementation, then generate the class, for example:

enter image description here

+3
source share

In IntellyJ IDEA 12, you can use the Push Members Down dialog:

 Refactor -> Pull Members Down... 

Then select the methods you want to click on the subclasses and click on "Refactor": http://clip2net.com/s/i6DK41

Note that it does not generate the stub method with the base class - it just moves it as it is. Thus, you will need to implement the stub yourself in the parent (root) class, for example:

 public boolean getRequiredDatabaseNameWhenPartitioned() { return true; } 

then use "Push members down", refactor and finally manually create the parent class method

0
source share

All Articles