# Remove Double Negations

# Description

Removes pairs of negations from boolean expressions until only zero or one negation is left.

# Benefits

Improves the readability of the code, by removing cascaded negations of boolean expressions.

# Tags

# Code Changes

# Example based on an even number of negations

Pre

boolean a = !!true; // 2 times

Post

boolean a = true; // removed negations completely

# Example based on an odd number of negations

Pre

boolean a = !!!true; // 3 times

Post

boolean a = !true; // reduced to one time

Use a Java Refactoring Tool

Automate this Refactoring system-wide

You can apply this refactoring for free with the jSparrow Eclipse IDE plug-in.
Install the plug-in for Eclipse IDE: Eclipse Marketplace.

a drawn cute bird pointing at a graph that shows positive results

# Properties

Property Value
Rule ID RemoveDoubleNegation
First seen in jSparrow version 2.7.0
Minimum Java version 1.1
Remediation cost 2 min
Links