Java

Java

By DeepSource

Redundant boolean literal JAVA-W1064

Bug risk Autofix

Boolean literals should not be used redundantly within expressions.

An entity that may evaluate to true or false can directly be used in an expression where a boolean value is expected. Boolean literals are almost never necessary in any expression.

Bad Practice

public void method() {
    if (returnsBoolean() == true) { //.. }
    if (boolVar || false) { // .. }
    if (boolVar && true) { // .. }
}

Recommended

Consider removing the redundant literals.

public void method() {
    if (returnsBoolean()) { //.. }
    if (boolVar) { // .. }
    if (boolVar) { // .. }
}