为什么三元运算符会因类型不匹配错误而失败? [英] Why does ternary operator fail with a type mismatch error?
本文介绍了为什么三元运算符会因类型不匹配错误而失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下简单的代码段:
I have the following simple code piece:
List<XXXXBean> queryPeriodData()
{
if (CollectionUtils.isEmpty(res))
{
return Collections.emptyList();
}
return res;
}
有效.
但是如果我改成这个,就会出现编译错误...
but if I change to this, there is a compile error...
return CollectionUtils.isEmpty(res) ? Collections.emptyList() : res;
错误消息是类型不匹配:无法从List< capture#1-of转换为Object>到List< XXXXBean>"
我不知道两种方法之间的区别.
I don't know the difference between the two way.
推荐答案
尝试集合.< XXXXBean> emptyList()
在语句中
这篇关于为什么三元运算符会因类型不匹配错误而失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文