java equivalent of Delphi NOT
In Delphi I can do the following with a boolean variable:
If NOT bValue then
begin
//do some stuff
end;
Does the equivalent in Java use the !?
If !(bValue) {
//do some stuff
}
Yes, but inside the bracket:
if (!bValue) {
}
You'd normally not use any sort of data type prefix in Java as well, so it would more likely be something like:
if (!isGreen) { // or some other meaningful variable name
}
You're close; the proper syntax is:
if (!bValue) {
//do some stuff
}
The entire conditional expression must be inside the parenthesis; the condition in this case involve the unary logical complement operator ! (JLS 15.15.6).
Additionally, Java also has the following logical binary operators:
& , ^ and | && and JLS 15.24 Conditional-or || There are also compound assignment operators (JLS 15.26.2) &= , |= , ^= .
Other relevant questions on stackoverflow:
== true and == false true and false ! when necessary if (!bValue) {
// do some stuff
}
链接地址: http://www.djcxy.com/p/73916.html
上一篇: 为什么&=操作符与&&不一样
下一篇: 相当于Delphi的Java
