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

25 lines
732 B
HTML

<html>
<body>
Reports <code>Optional</code> call chains that can be replaced with a sequence of <code>if</code> statements.
<p>Example:</p>
<pre><code>
return Optional.ofNullable(name)
.map(this::extractInitials)
.map(initials -> initials.toUpperCase(Locale.ENGLISH))
.orElseGet(this::getDefault);
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
if (name != null) {
String initials = extractInitials(name);
if (initials != null) return initials.toUpperCase(Locale.ENGLISH);
}
return getDefault();
</code></pre>
<!-- tooltip end -->
<p>
This inspection can help to downgrade for backward compatibility with earlier Java versions.
</p>
<p><small>New in 2020.2</small></p>
</body>
</html>