Generating Delegate Methods In Java Using Intellij
If you are implementing a decorator pattern, you would have to implement one or more interfaces. If the interface has large number of methods, delegating each of them might be troublesome and error prone. Since there is no good way in java to implement delegates (implementing a proxy with an invocation handler is a workaround :)), a better option would be to take help of the IDE to be sure that the implementation is not error prone. Here is how to do it using Intellij IDE
- 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.
- 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.
- 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.
- Select the desired methods. For multiple selection, use Ctrl and Shift keys. Click OK.