Files
openide/java/java-impl/resources/inspectionDescriptions/NegatedConditional.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

30 lines
1.1 KiB
HTML

<html>
<body>
Reports conditional expressions whose conditions are negated.
<p>Flipping the order of the conditional expression branches usually increases the clarity of such statements.</p>
<!-- tooltip end -->
<p>
Use the <b>Ignore '!= null' comparisons</b> and <b>Ignore '!= 0' comparisons</b> options to ignore comparisons of the form
<code>obj != null</code> or <code>num != 0</code>.
Since <code>obj != null</code> effectively means "obj exists",
the meaning of the whole expression does not involve any negation
and is therefore easy to understand.
<p>
The same reasoning applies to <code>num != 0</code> expressions, especially when using bit masks.
<p>
These forms have the added benefit of mentioning the interesting case first.
In most cases, the value for the <code>== null</code> branch is <code>null</code> itself,
like in the following examples:
<pre><code>
static String getName(Person p) {
return p != null ? p.getName() : null;
}
static String getExecutableString(int fileMode) {
return (fileMode & 0b001001001) != 0 ? "executable" : "non-executable";
}
</code></pre>
</body>
</html>