Let's say I have a class with multiple constructors, one of which is a copy-constructor (to copy an object):
public class Rectangle {
int width, height;
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}
public Rectangle(Rectangle source) {
this(source.width, source.height);
}
}
Is there any way I can make check if source
is null
in the copy-constructor and throw an IllegalArgumentException
if it is? Because the other constructor call has to be the first statement in my constructor.
this(...)
after another statement. – Hardpressednull
is passed. – Moue