Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate constructors in eclipse

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?

like image 766
akshay Avatar asked Aug 14 '10 19:08

akshay


People also ask

What is the shortcut to create constructor 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.

Why do we generate constructor from superclass?

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.


1 Answers

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.

like image 152
kylc Avatar answered Sep 27 '22 21:09

kylc