Oxobo
Oxobo

Reputation: 673

How to add abstract method for a new implemented method in subclass to interface or abstract class in Intellij Idea?

If a class is implementing a certain interface or extending a class with abstract methods, it has to implement the methods of such interface or class. IntelliJ IDEA creates the implemented methods, with CTRL+i or ALT+INSERT. How about vice versa ?

For example I have a class that implements my interface.

After adding a new method definition in the class, how can I fast-add an abstract method in the interface?

Is there any short key for it?

Upvotes: 3

Views: 1854

Answers (2)

Mureinik
Mureinik

Reputation: 311393

One easy way of doing this is to add the @Override annotation to the new method you just added, which will cause a compilation error (since this method doesn't override anything). Then, place you carret on the annotation and press ALT+ENTER. IntelliJ will open a context menu, where one of the options is "Pull method 'methodName' to 'InterfaceName'" - choose it to get your method declared in the interface/abstract class you're extending.

Upvotes: 2

GhostCat
GhostCat

Reputation: 140457

A potential workaround: simply put @Override on that method in your class.

That will lead to a compile error; and I am sure that IntelliJ would then offer you to add that method to your interface. (that is what I would do in eclipse).

Upvotes: 1

Related Questions