svachon
svachon

Reputation: 7716

What does this boolean setter mean?

I am assigned some maintenance task for a Java program and found this:

public void setActiveCode(boolean isActiveCode) {
    this.isActiveCode = isActiveCode & Boolean.TRUE;
}

The type of this.isActiveCode is a boolean, The same concept is repeated for every boolean setters in the class. I can't figure out why it is done this way and I can't ask the original developer.

Would there be any valid reason for doing this?

Upvotes: 3

Views: 123

Answers (2)

jason
jason

Reputation: 241641

Would there be any valid reason for doing this?

No. This is just more verbose code with zero gain in clarity (and arguably a loss in clarity since here you are wondering what it's all about).

It reminds me of

public boolean isTrue(boolean b) {
    if(b == true) {
        return true;
    }
    else {
        return false;
    }
}

which unfortunately you will see in the wild from time to time. It's just so sad.

Upvotes: 9

s.d
s.d

Reputation: 29436

Its weird. Booleans can be used with logical &, but this is useless because a & true = a. Seems to be a developer specific OCD.

Upvotes: 1

Related Questions