Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

Generating Methods to Implement and Override

When you extend a class or implement an interface, you have abstract methods that you need to implement and possibly non-abstract methods that you can override. The IDE has several tools that help you generate these methods in your class:

  • Editor hints. When you add the implements or extends clause, a lightbulb ( keegan_05_01.jpg ) icon appears in the left margin. You can click this icon or press AltEnter to view a hint to implement abstract methods. If you select the hint and press Enter, the IDE generates the methods for you. This hint only is available when your cursor is in the line of the class declaration.
  • Code completion. You can generate methods to implement and override individually by pressing Ctrl-Space and choosing the methods from the code completion box. As shown in Figure 5-7, methods to implement or override are marked implement and override, respectively.
    keegan_fig05_07.jpg

    Figure 5-7 Code completion box showing methods to implement and methods available to be overridden

  • Override and Implement Methods dialog box. You can use this dialog box (shown in Figure 5-8) for generating any combination of the available implementable or overridable methods. This feature also enables you to generate calls to the super implementation of the methods within the body of the generated methods. To open this dialog box, choose Source | Override Methods or press Ctrl-I. To select multiple methods, use Ctrl-click.
keegan_fig05_08.jpg

Figure 5-8 Override and Implement Methods dialog box

  • + Share This
  • 🔖 Save To Your Account