[英]java equivalent of Delphi NOT
In Delphi I can do the following with a boolean variable: 在Delphi中,我可以使用布尔变量执行以下操作:
If NOT bValue then
begin
//do some stuff
end;
Does the equivalent in Java use the !? Java中的等效项是否使用!?
If !(bValue) {
//do some stuff
}
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 ). ( JLS 15.15.6 )。
Additionally, Java also has the following logical binary operators: 此外,Java还具有以下逻辑二进制运算符:
&
, ^
and |
&
, ^
和|
&&
and JLS 15.24 Conditional-or ||
&&
和JLS 15.24有条件或||
There are also compound assignment operators ( JLS 15.26.2 ) &=
, |=
, ^=
. 也有复合赋值运算符( JLS 15.26.2 )
&=
, |=
, ^=
。
== true
and == false
== true
和== false
true
and false
true
与false
显式比较 !
!
when necessary 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: 通常,您也不会在Java中使用任何类型的数据类型前缀,因此很有可能是这样的:
if (!isGreen) { // or some other meaningful variable name
}
if (!bValue) {
// do some stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.