且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java三元运算符(?:)不起作用;第二个或第三个操作数返回布尔值

更新时间:2023-02-06 18:06:14

Java三元操作条件的使用应该类似于

Usage of Java ternary operation condition should looks like

result = testCondition ? value1 : value2

它是java语言规范。

it's java-language specification.

平等,关系和条件运算符


在以下示例中,
此运算符应该读作:如果 someCondition true ,请将 value1
值分配给结果。否则,赋值 value2
结果

In the following example, this operator should be read as: "If someCondition is true, assign the value of value1 to result. Otherwise, assign the value of value2 to result