如何让一个int变量引用禁止引用某个特定值
来源:百度知道 编辑:UC知道 时间:2024/06/01 16:50:15
比如不让int a不能引用1
if (a==1) {
System.out.println("变量a的值不能为1");
return;
}
你是不是故意的?直接不容许赋值不就可以吗?!
public class test{
private int i;
public void setI(int a){
this.i = (a != 1)?a:this.i;
}
public int getI(){
return this.i;
}
}