mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
26 lines
1.1 KiB
HTML
26 lines
1.1 KiB
HTML
<html>
|
|
<body>
|
|
Reports public methods that accept a <code>boolean</code> parameter.
|
|
<p>It's almost always bad practice to add a <code>boolean</code> 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 <code>boolean</code> stands for without looking at
|
|
the source or documentation.</p>
|
|
<p>This problem is also known as <a href="https://ariya.io/2011/08/hall-of-api-shame-boolean-trap">the boolean trap</a>.
|
|
The <code>boolean</code> parameter can often be replaced with an <code>enum</code>.</p>
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
// Warning: it's hard to understand what the
|
|
// boolean parameters mean when looking at
|
|
// a call to this method
|
|
public boolean setPermission(File f,
|
|
int access,
|
|
boolean enable,
|
|
boolean ownerOnly) {
|
|
// ...
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>
|
|
Use the <b>Only report methods with multiple boolean parameters</b> option to warn only when a method contains more than one boolean parameter.
|
|
<p>
|
|
</body>
|
|
</html> |