Files
openide/java/java-impl/resources/inspectionDescriptions/ConditionalCanBeOptional.html
2025-02-05 04:43:28 +00:00

21 lines
945 B
HTML

<html>
<body>
Reports null-check conditions and suggests replacing them with <code>Optional</code> chains.
<p>Example:</p>
<pre><code>
return str == null ? "" : str.trim();
</code></pre>
<p>After applying the quick-fix:</p>
<pre><code>
return Optional.ofNullable(str).map(String::trim).orElse("");
</code></pre>
<p>While the replacement is not always shorter, it could be helpful for further refactoring
(for example, for changing the method return value to <code>Optional</code>).</p>
<p>Note that when a not-null branch of the condition returns null, the corresponding mapping step will
produce an empty <code>Optional</code> possibly changing the semantics. If it cannot be statically
proven that semantics will be preserved, the quick-fix action name will contain the "(may change semantics)"
notice, and the inspection highlighting will be turned off.</p>
<!-- tooltip end -->
<p><small>New in 2018.1</small></p>
</body>
</html>