问题
I have the following simple code piece:
List<XXXXBean> queryPeriodData()
{
if (CollectionUtils.isEmpty(res))
{
return Collections.emptyList();
}
return res;
}
It works.
but if I change to this, there is a compile error...
return CollectionUtils.isEmpty(res) ? Collections.emptyList() : res;
error message is "Type mismatch: cannot convert from List< capture#1-of ? extends Object> to List< XXXXBean>"
I don't know the difference between the two way.
回答1:
try Collections.<XXXXBean>emptyList()
in the statement
来源:https://stackoverflow.com/questions/25799249/why-does-ternary-operator-fail-with-a-type-mismatch-error