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;
}
}
To navigate to the implementation, press Ctrl+Alt+B .
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.
Press Ctrl+Shift+R and then choose Convert Abstract Class to Interface. Choose Refactor | Convert Abstract Class to Interface from the main menu.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With