13

For example I have many classes than implement my interface. After adding new method definition in the interface, how can I fast-add blank interface implementations for all that classes?

4 Answers 4

27

Alt+Enter on the new method in the interface, Implement method:

enter image description here

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

Sign up to request clarification or add additional context in comments.

Comments

6

I think the best you can do comes from their code generation tutorial, particularly by using

Ctrl+O

in an implementing class. Otherwise I'm not aware of a way to generate an entire class.

2 Comments

That's the question. I know that I can go through all classed and insert implementation. But I want ability to implement methods for all classes from interface.
@Jack, right. I believe that is not possible, and this is the closest alternative.
5

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

Implement interface Please note that my caret can't be seen but it's between the h and a of Shape

IntelliJ will then prompt you for a class name and which methods to include in the implementation, then generate a class, like this:

enter image description here

Comments

0

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

Refactor -> Pull Members Down... 

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

Note that it doesn't generate the stub method by base class - it just moves it as is. So you'll need to implement the stub by yourself in the parent (root) class, e.g.:

public boolean getRequiredDatabaseNameWhenPartitioned() {
  return true;
}

then use "Push members down", refactor, and finally make the method of the parent class abstract manually

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.