我知道如果行如
if(condition)
return A;
else
return B;
可以写成 return (condition? A : B);
那如果不要返回值,只是为了
if(condition)
A();
else
B();
有没有简写的方法的?
if(condition)
return A;
else
return B;
可以写成 return (condition? A : B);
那如果不要返回值,只是为了
if(condition)
A();
else
B();
有没有简写的方法的?
(condition)?a:b它只是一个三项表达式,不能调用方法的
public static void main(String[] args){
boolean bl;
Test t = new Test();
int a = (1==1)?t.getInt1():t.getInt2();
}
public int getInt1(){
System.out.println("------1");
return 1;
}
public int getInt2(){
System.out.println("------2");
return 2;
}
}不好意思,信口雌黄了
可以的。