IntelliJ IDEA 2018.3 Help

Implement Methods of an Interface or Abstract Class

If a class is declared as 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 stubs for implemented methods, with the default return values for the primitive types, and null values for the objects.

To implement required methods:

  1. On the Code menu, click Implement methods (Ctrl+I). Alternatively, you can right-click anywhere in the class file, then click Generate (Alt+Insert), and select Implement methods.

  2. Select the methods to implement. If necessary, select the Copy JavaDoc check box to insert JavaDoc comments for the implemented interface or abstract class.

  3. Click OK.

Change method body

The code template used for implementing methods (Implemented method body) accepts predefined template variables from the File Header include template (such as, ${USER}, ${DATE}, etc.)

For example, consider the following file template:

#if ( $RETURN_TYPE != "void" )return $DEFAULT_RETURN_VALUE;#end // TODO ($USER, $DATE):To change the body of an implemented method, use File | Settings - Editor - File and Code Templates.

Provided that the implemented interface contains two methods, this template expands into the following code:

@Override public void hunt() { // TODO (wombat, 9/21/12): To change the body of an implemented method, use File | Settings - Editor - File and Code Templates. } @Override public String sniff() { return null; // TODO (wombat, 9/21/12): To change body of implemented methods use File | Settings - Editor - File and Code Templates. }
Last modified: 1 February 2019