mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 08:51:02 +07:00
30 lines
1.1 KiB
HTML
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> |