public class TestClass {
private int x;
private int y;
public TestClass(int x, int y) {
if (isParamNotValid(x) || isParamNotValid(y))
throw new IllegalArgumentException("Input parameters are not valid! Need to be bigger zero");
this.x = x;
this.y = y;
}
private boolean isParamNotValid(int p) {
return p < 0;
}}
我会这样做: