Invert Boolean
The Invert Boolean refactoring lets you change the sense of a Boolean method or variable to the opposite one.
Place the caret at the name of the method or variable that you want to refactor.
On the main or context menu, select
.In the dialog that opens, specify the name for the inverted method or variable.
Example
Before | After |
---|---|
private double a;
...
public boolean method() {
if (a > 15 && a < 100) {
a = 5;
return true;
}
return false;
}
|
private double a;
...
public boolean method() {
if (a > 15 && a < 100) {
a = 5;
return false;
}
return true;
}
|
boolean b = true;
...
public double method() {
...
b = false;
...
}
|
boolean b = false;
...
public double method() {
...
b = true;
...
}
|
Last modified: 01 August 2022