booleanWithAVeryLongName

booleanWithAVeryLongName

有没有一种简短的方法可以切换 boolean 值?

使用整数,我们可以执行以下操作:

int i = 4;
i *= 4; // equals 16
/* Which is equivalent to */
i = i * 4;

那么,还有一些适合 boolean 值的东西(例如int的*=运算符)吗?

在C++中:
bool booleanWithAVeryLongName = true;
booleanWithAVeryLongName = !booleanWithAVeryLongName;
// Can it shorter?
booleanWithAVeryLongName !=; // Or something?

在Java中:
boolean booleanWithAVeryLongName = true;
booleanWithAVeryLongName = !booleanWithAVeryLongName;
// Can it shorter?
booleanWithAVeryLongName !=; // Or something?

最佳答案

没有这样的运算符,但是要短一些:booleanWithAVeryLongName ^= true;

关于java - C++/Java : Toggle boolean statement?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3070187/

10-13 05:41