IntelliJ IDEA 2016.1 Help

Generating Delegation Methods

You can create methods that delegate behavior to the fields or methods of your class. This approach makes it possible to give access to the information of a field or method without direct exposing this field or method.

To create delegation methods

  1. On the main menu, choose Code | Generate. Alternatively, right-click the editor and choose Generate on the context menu, or use Alt+Insert keyboard shortcut.
  2. In the pop-up list that is displayed in the editor, select Delegate Methods. Select Target To Generate Delegates For dialog appears, displaying the list of objects to be delegated to.
  3. Select the target field or method, and click OK. The Select Method To Generate Delegation For dialog appears, displaying the list of methods to delegate.
  4. Select the desired methods. For multiple selection, use Ctrl and Shift keys. Click OK.


Currency class has a field calendar of the type Calendar. To gain access to certain functionality of the Calendar class from the Currency class, we need to create a new method that will delegate the request to calendar.

Calendar calendar;publicint get(inti) {returncalendar.get(i); }
Last modified: 13 July 2016