可以的。。
如果构造函数里需要一些逻辑处理,可以使用return语句。
使用return 不一定要返回值。
我这里举个例子:
public class Return {
int x=0;
Return(int x){
if(x>10)
return;
else {
this.x=x;
}
}
public static void main(String[] args) {
Return r1 = new Return(12);
System.out.println("r1---"+r1.x);
Return r2 = new Return(9);
System.out.println("r2---"+r2.x);
}
}
输出结果:
r1---0
r2---9 |