java三元运算符 [英] java ternary operator
本文介绍了java三元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以解释为什么这段代码?
Can someone explain why this code?
Collection c = (5 == 5) ? new ArrayList() : new HashSet();
产生以下编译错误:
不兼容的条件操作数类型ArrayList和HashSet
Incompatible conditional operand types ArrayList and HashSet
由于我不理解的原因,以下修复了问题
For reasons that I don't understand, the following fixes the problem
Collection c = (5 == 5) ? (Collection) new ArrayList() : new HashSet();
我正在使用Java 1.4。
I'm using Java 1.4.
推荐答案
这是1.4中的错误,并已根据 bugreport 5080917 。
This was a bug in 1.4 and has been fixed according bugreport 5080917.
评估这是一个错误。
xxxxx @ xxxxx 2004-07-30
xxxxx@xxxxx 2004-07-30
这篇关于java三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文