Inspectopedia Help

Unary plus

Reports usages of the + unary operator. The unary plus is usually a null operation, and its presence might represent a coding error. For example, in a combination with the increment operator (like in +++) or with the equal operator (like in =+).

Example:

void unaryPlus(int i) { int x = + +i; }

The following quick fixes are suggested:

  • Remove + operators before the i variable:

    void unaryPlus(int i) { int x = i; }
  • Replace + operators with the prefix increment operator:

    void unaryPlus(int i) { int x = ++i; }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

UnaryPlus
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Numeric issues

Use the checkbox below to report unary pluses that are used together with a binary or another unary expression. It means the inspection will not report situations when a unary plus expression is used in array initializer expressions or as a method argument.

Inspection options

Here you can find the description of settings available for the Unary plus inspection, and the reference of their default values.

Only report in confusing binary or unary expression context

Default: Selected

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Can be installed with plugin:

Java, 242.22892

Last modified: 11 September 2024