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

34 lines
1.1 KiB
HTML

<html>
<body>
Reports <code>instanceof</code> with patterns and suggests converting them to ordinary <code>instanceof</code> with casts.
<p>This inspection makes it possible to move <code>instanceof</code> with patterns to a codebase using an earlier Java version
by applying the quick-fix.</p>
<p>
Note that the result can be not completely equivalent to the original <code>instanceof</code> with patterns when
a complex expression before <code>instanceof</code> is used. In this case this expression will be reevaluated.
</p>
<!-- tooltip end -->
<p>Example:</p>
<pre><code>
if (object instanceof String txt && txt.length() == 1) {
System.out.println(txt);
} else {
return;
}
System.out.println(txt);
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
if (object instanceof String && ((String) object).length() ==1) {
String txt = (String) object;
System.out.println(txt);
} else {
return;
}
String txt = (String) object;
System.out.println(txt);
</code></pre>
<!-- tooltip end -->
<p><small>New in 2023.1</small></p>
</body>
</html>