有没有办法用 && 或 || 表示逻辑不
Is there a way to represent logical not with && or ||
有没有办法用&&
或||
或if
或?:
[=20=之类的语句来表示逻辑非]
我想以其他方式实现:
boolean isRunning = true;
startButton.setEnabled(!isRunning); // <<== ???
假设您将此作为练习,三元运算符可让您以简单直接的方式替换 !
:
startButton.setEnabled(isRunning ? false : true);
就单独使用&&
和||
而言,这对操作符不是functionally complete,即有些操作不能通过使用一系列&&
s 和 ||
s 单独; not !
操作是不能用 ands 和 ors 实现的操作之一。
有没有办法用&&
或||
或if
或?:
[=20=之类的语句来表示逻辑非]
我想以其他方式实现:
boolean isRunning = true;
startButton.setEnabled(!isRunning); // <<== ???
假设您将此作为练习,三元运算符可让您以简单直接的方式替换 !
:
startButton.setEnabled(isRunning ? false : true);
就单独使用&&
和||
而言,这对操作符不是functionally complete,即有些操作不能通过使用一系列&&
s 和 ||
s 单独; not !
操作是不能用 ands 和 ors 实现的操作之一。