Inspectopedia
 
2024.3

Unnecessary parentheses

Info
Last modified: 03 December 2024

Reports any instance of unnecessary parentheses.

Parentheses are considered unnecessary if the evaluation order of an expression remains unchanged after you remove the parentheses.

Example:

After quick-fix is applied:

Configure the inspection:

  • Use the Ignore clarifying parentheses option to ignore parentheses that help clarify a binary expression. Parentheses are clarifying if the parenthesized expression is an instanceof expression that is a part of a larger expression or has a different operator than the parent expression.

  • Use the Ignore parentheses around the condition of conditional expressions option to ignore any parentheses around the condition of conditional expressions. Some coding standards specify that all such conditions must be surrounded by parentheses.

  • Use the Ignore parentheses around single no formal type lambda parameter option to ignore parentheses around a single lambda parameter within a lambda expression.