IntelliJ IDEA 2023.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; ... }

Invert boolean dialog

This dialog appears when you use the Invert boolean refactoring.

Item

Description

Name of inverted method/field

Specify the name for the inverted method or field.

Last modified: 11 February 2024