IntelliJ IDEA 14.1.1 Help

Implementing Methods of an Interface

In this section:

Overview

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 of the implemented methods, with the default return values for the primitive types, and null values for the objects.

Implementing methods

To implement method of an interface or abstract class , follow these steps:

  1. Do one of the following:
    • On the main menu, choose Code | Implement method.
    • Press Ctrl+I
    • Right-click the editor, choose Generate on the context menu, or press Alt+Insert, and choose Implement methods.

    The Select methods tTo implement dialog appears, displaying the list of classes and interfaces with the methods that can be implemented.

  2. Select one or more methods to implement. For multiple selection, use Ctrl and Shift keys.
  3. If necessary, select the check box Copy JavaDoc to insert JavaDoc comments from the implemented interface of abstract methods (if any).
  4. Click OK.

Changing method body

File template responsible for implementing a method (Implemented method body) accepts predefined template variables from "File Header" (File | Settings - Editor - File and Code Templates - Code - File Header ), e.g. ${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 an implemented interface contains two methods, this template expands into the following code:

@Override public void hunt() { // TODO (mio, 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 (mio, 9/21/12): To change body of implemented methods use File | Settings - Editor - File and Code Templates. }

See Also

Web Resources:

Last modified: 6 April 2015