If I have an interface with a few methods. Sometimes I need to create a new implementation of the interface which wraps another instance of the interface and delegates most of the methods to the wrapped instance. Then I would change a couple of the implementations, maybe not delegating them.
A classic example would be the Collections.unmodifiableXXX()
methods in the JDK which block access to the modification methods.
Does IntelliJ have any code assistance that will generate a delegate implementation of the interface and then I can just tweak a couple of methods?
By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again.
From the main menu, select Code | Generate Alt+Insert to open the popup menu with available constructs that you can generate.
You can use ⌘N (macOS), or Alt+Insert (Windows/Linux) for the Generate menu and then select Constructor , Getter , Setter or Getter and Setter .
You can do it in two stages. First implement the interface and then introduce delegation
Code|Delegate Methods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With