Extract constructor parameters to class fields

Answered

Hi

Is there a feature to extract constructor parameters to class fields and assign them?

From:

public class Rect {
public Rect(int x, int y, int w, int h) {
}
}

To:

public class Rect {
private int x;
private int y;
private int w;
private int h;

public Rect(int x, int y, int w, int h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
}
0
2 comments

Hi Sauli,

Place the caret on the constructor's name and invoke Alt+Enter (or click on the lightbulb), then choose the "Bind constructor parameters to fields" option.

0

Thanks, excellent tool. 

Yesterday I tried just that, but I only got an error message saying "caret should be on .....".

Keep up the good work. 

-- 

Sauli

0

Please sign in to leave a comment.