mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
34 lines
1.1 KiB
HTML
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> |