[英]What is the return value of this conditional (groovy script)
What will be the return value of this if/else
statement? if/else
语句的返回值是多少?
if (salary <= 3000) {
return discount < 0.40
}
else {
return discount < 0.60
}
I'm not sure if the return value of each if
and else
will be a boolean
or 0.40
and 0.60
? 我不确定每个
if
和else
的返回值是boolean
还是0.40
和0.60
?
It is a boolean. 这是一个布尔值。 The
<
, >
, !=
, >=
, ==
, <=
expressions will evaluate to a boolean value: <
, >
, !=
, >=
, ==
, <=
表达式将计算为布尔值:
def mustDiscount(salary, discount = 0.5) {
if (salary <= 3000) {
return discount < 0.40
}
else {
return discount < 0.60
}
}
mustDiscount(2000).with {
assert it in Boolean
assert !it
}
mustDiscount(4000).with {
assert it in Boolean
assert it
}
The return type for that would be a boolean (true or false), both in the if block and else block. 在if块和else块中,其返回类型均为布尔值(true或false)。
Also return discount == 0.50
would return a boolean. 同样,如果
return discount == 0.50
,则返回布尔值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.