Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

intelij idea shortcut to implement interface as a new class

suppose i have a interface like this:

public interface Dumb{
String getDumbName();
}

Is there any shortcut or menu in intellij-idea to create new classes implementing the interface with dummy implement methods like this:

 public class Dumber{
   public String getDumbName(){
return null;
}
    }
like image 231
redbeard1970 Avatar asked Feb 04 '17 14:02

redbeard1970


People also ask

How do I jump to implement an interface in IntelliJ?

To navigate to the implementation, press Ctrl+Alt+B .

How do you implement an interface to a class?

To declare a class that implements an interface, you include an implements clause in the class declaration. Your class can implement more than one interface, so the implements keyword is followed by a comma-separated list of the interfaces implemented by the class.

How do I change class to interface in IntelliJ?

Press Ctrl+Shift+R and then choose Convert Abstract Class to Interface. Choose Refactor | Convert Abstract Class to Interface from the main menu.

Where is the implementation class of interface in IntelliJ?

Press Ctrl+F12 or choose Navigate | Implementation(s) from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.


1 Answers

There are multiple ways to go about this.

On the interface name itself, you can hit Alt+Enter (Option+Enter on Mac), then pick 'Implement interface'. IDEA will prompt for a class name and a package to put the new class in, then generate an implementation class.

Alternatively, create the class, then add implements Dumb after the name (im<tab> Dumb). IDEA will complain that your class doesn't implement the correct methods, and offer (Alt+Enter Enter Enter) to generate them for you. Hitting Ctrl+I or clicking 'Implement methods' in the Code menu also works.

like image 172
Wander Nauta Avatar answered Nov 07 '22 12:11

Wander Nauta