IntelliJ IDEA 2021.3 Help

Invert Boolean

The Invert Boolean refactoring lets you change the sense of a Boolean method or variable to the opposite one.

  1. Place the caret at the name of the method or variable that you want to refactor.

  2. On the main or context menu, select Refactor | Invert Boolean.

  3. In the dialog that opens, specify the name for the inverted method or variable.

  4. Preview and apply changes.

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