美文网首页
Incompatible operand types Strin

Incompatible operand types Strin

作者: 去往自由的路上 | 来源:发表于2018-08-24 18:08 被阅读0次
long a = 5;
String name = "Tom";
int b = 1;

b >= 0 ? a : name;

三目运算符 (表达式1)?(表达式2):(表达式3),计算方法是这样的:表达式1是一个逻辑表达式,如果其值为true,则整个表达式的值为表达式2的值,否则为表达式3的值

解决方式:(表达式2)和(表达式3)改为同一数据类型即可。如下:

b >= 0 ? a +"" : name;

相关文章

网友评论

      本文标题:Incompatible operand types Strin

      本文链接:https://www.haomeiwen.com/subject/rysiiftx.html