If I start from an empty class (TestClass) in Netbeans and add the following empty constructor:
public void TestClass(String a, String b) {
}
is there a way to have netbeans automagically generate:
private final String a;
private final String b;
public void TestClass(String a, String b) {
this.a = a;
this.b = b;
}
I know that I can first create the 2 members and ask netbeans to auto-generate the constructor but I'm asking for the other way round.
For example, in eclipse, this can be achieved by pressing CTRL+1 on the constructor's argument > assign parameter to new field.
from: https://coderwall.com/p/oyanzg
Just point the cursor at the point where you want the generated code to appear, and press Alt + Insert (or select Source -> Insert Code). The following menu will appear, where you can choose to generate whatever you want:
You can write the empty constructor with the required signature. Then set the cursor next to a parameter and press Alt+ENTER.
NetBeans will ask to create a new field. Press ENTER and NetBeans will write the code for you.
I think you have to do it for each parameter separately, but I'm not sure.
Generally, Alt+ENTER in NetBeans is similar to Ctrl+1 in Eclipse, also at other places.
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