public class Test {
public static void main(String[] args) {
Object o1=true? new Integer(1): new Double(2.0);
Object o2;
if(true){
o2=new Integer(1);
}else {
o2=new Double(2.0);
}
System.out.println(o1);
System.out.println(" ");
System.out.println(o2);
}
}
三元运算符优先级----高于赋值运算符相当于
Object o1=(true? new Integer(1): new Double(2.0));
三元运算符之间的类型自动从低往高转换Integer自动转换为Double
最后输出1.0 1