Java ternary (immediate if) evaluation

前端 未结 3 1458
南方客
南方客 2020-11-30 09:41

I can\'t find the relevant portion of the spec to answer this. In a conditional operator statement in Java, are both the true and false arguments evaluated?

So could

3条回答
  •  时光取名叫无心
    2020-11-30 10:27

    No, it couldn't. That's the same as:

    Integer test = null;
    if ( test != null ) { 
        test = test.intValue();
    }
    else {
        test = 0;
    }
    

提交回复
热议问题