mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
26 lines
1014 B
HTML
26 lines
1014 B
HTML
<html>
|
|
<body>
|
|
Reports <code>null</code> assigned to an <code>Optional</code> variable or returned from a method returning <code>Optional</code>.
|
|
<p>It's recommended that you use <code>Optional.empty()</code> (or <code>Optional.absent()</code> for Guava) to denote an empty value.</p>
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
Optional<Integer> foo(boolean flag) {
|
|
return flag ? Optional.of(42) : null;
|
|
}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
Optional<Integer> foo(boolean flag) {
|
|
return flag ? Optional.of(42) : Optional.empty();
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>Configure the inspection:</p>
|
|
<p>
|
|
Use the <b>Report comparison of Optional with null</b> option to also report comparisons like <code>optional == null</code>. While in rare cases (e.g. lazily initialized
|
|
optional field) this might be correct, optional variable is usually never null, and probably <code>optional.isPresent()</code> was
|
|
intended.
|
|
</p>
|
|
<p><small>New in 2017.2</small>
|
|
</body>
|
|
</html> |