16
可能重复:
Tricky ternary operator in Java - autoboxing的Java零为int条件运算问题
我们知道int roomCode = null;
不是由编译器允许在。
然后为什么代码1没有给出编译器错误,当代码2。
代码1:
int roomCode = (childCount == 0) ? 100 : null;
代码2:
int roomCode = 0;
if(childCount == 0) roomCode = 100;
else roomCode = null; // Type mismatch: cannot convert from null to int
一个很好的问题。 – 2012-02-23 05:54:12
也许与自动装箱相关,但我不知道如何... – talnicolas 2012-02-23 05:56:25
当它采用该路径时,null值会作什么评估? – Mysticial 2012-02-23 05:58:35