So code reviewers are complaining about code like this:
boolean myFlag = false;
They are saying it should be:
boolean myFlag = Boolean.FALSE;
Is this just some fetish with not using keywords or is there a valid reason to do this?
No, that's completely pointless. It would make sense to use:
// Note capital B Boolean myFlag = Boolean.FALSE;
to avoid the call to Boolean.valueOf
(autoboxing) but in your code there is no boxing, and their suggestion introduces an unnecessary unboxing operation.
As ever though, if someone suggests something and you don't understand why, your first port of call should be asking them.
There's nothing wrong with using keyword false. In fact, in your code you'd be silly to use Boolean.False since there is an implicit auto unboxing that has to occur to assign it to your primitive field/variable (Boolean.False is a Boolean and not a boolean).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With