Issue
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.
Solution
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.
Answered By - Puce
Answer Checked By - Marie Seifert (JavaFixing Admin)