三元布尔评估怪癖

时间:2019-04-15 05:13:23

标签: java

1==1 ? true : null  // OK, produces true
1==1?true:(Boolean)null // OK, produces true
1==2?true:(Boolean)null // NullPointerException
1==2?true:null // OK, produces null
1==2?(Boolean)true:(Boolean)null // OK, produces null

有人知道为什么只有第三个会产生NullPointerException吗?

0 个答案:

没有答案
相关问题