Overriding and Implementing Methods
See Also
The IDE has the following two mechanisms to generate code for implementing
or overriding methods that are defined in other classes:
- The code completion,
which you can use to generate code to implement or override a method.
- The Override Methods command (Ctrl-I), which you can use to generate code to implement or
override multiple methods at the same time.
To use code completion to generate code to override or implement a method:
- In the class declaration, use the extends keyword to extend a class,
or use the implements keyword to implement an interface.
- At the beginning of the line where you want to place the method, press
Ctrl-Spacebar and select the method from the code completion dialog box.
The method declaration is inserted into the file. You can then code
the method body in the Source Editor.
To use the Override Methods command:
- In the class declaration, use the extends keyword to extend a class,
or use the implements keyword to implement an interface.
- Right-click a Java file in the Projects window and choose
Source > Override Methods
from the pop-up menu or press Ctrl-I.
The Override and Implement Methods dialog box is displayed with all of the available
methods listed in the Available Superclass and Interface Methods panel. The
IDE filters out final, static, private, and package-private methods.
Use the checkboxes at the top of the dialog box to fine-tune the methods
displayed in the list:
- Select Show Superclasses and Interfaces to group the methods by their
class and interface.
- Select Only Abstract to show only methods that are explicitly declared
abstract.
- In the Available Superclass and Interface Methods panel, select the methods
you want to override.
- If you want the methods that are generated in your class to contain calls
to the superclass method, select the Generate Super Calls checkbox.
- To copy the Javadoc comments for the selected methods into your source file,
select the Copy Javadoc checkbox.
- Click OK.
The methods are created in your class's source file with proper declarations
and empty bodies or superclass calls. You can then code
the method body in the Source Editor.
Overridden methods are marked with a
glyph in the method's left margin in the Source Editor. Methods that are implemented
from an interface or an abstract class are marked with
glyph. Hold the pointer over the glyph to view a tooltip with the fully-qualified
name of the class that contains the overriden or implemented method. .
- See Also
- Using Code Completion
- Using Editor Hints to Fix Code
- Using the Word Match Feature
Legal Notices