Reputation: 59
How can I simplify this:
Is it necessary to have two different constructors with just one little difference.
Is there a way to simplify that using just one of them?
public class MyCostructor {
public MyCostructor(int w, int h, String name) {
this.w = w;
this.h = h;
this.name = name;
}
public MyCostructor(int w, int h) {
this.w = w;
this.h = h;
}
}
Upvotes: 3
Views: 503
Reputation: 85779
Use this()
in your constructor:
public MyCostructor(int w, int h, String name) {
this(w, h);
this.name = name;
}
public MyCostructor(int w, int h) {
this.w = w;
this.h = h;
}
Upvotes: 3