I have a class A and B.M extends A. Now I want a create a constructor of B using code generation option of eclipse which accepts parameters and set values of all fields of B (I mean it should also set fields inherited from A).
Is there any shortcut to generate such code in eclipse?
To generate constructor(s) from a superclass, just press Alt+Shift+S, C (or alternatively select Source > Generate Constructor from Superclass… from the application menu). A dialog pops up allowing you to select the constructor(s) you'd like to create.
And creating constructors from a superclass can take even longer because the superclass can define multiple constructors that you need to reimplement. That is why Eclipse has two features to help you generate these constructor instantly: Generate Constructor using Field and Generate Constructor from Superclass.
Right click in the editor and click "Source -> Generate Constructor using Fields". You can select the super constructor to use and also select instance variables to add to the constructor.
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