boolean
parameter.
It's almost always a bad practice to add a boolean
parameter to a public method (part of an API) if that method is not a setter.
When reading code using such a method, it can be difficult to decipher what the boolean
stands for without looking at
the source or documentation.
This problem is also known as the boolean trap.
The boolean
parameter can often be profitably replaced with an enum
.
Example:
// Warning: it's hard to understand what boolean parameters mean when reading the code public boolean setPermission(File f, int access, boolean enable, boolean owneronly) { ... }
Use the option below to only warn when a method contains more than one boolean parameter.