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

26 lines
907 B
HTML

<html>
<body>
Reports anonymous classes which could be transformed to a constructor or a factory method call with a lambda expression argument.
<p>The following classes are reported by this inspection:
<ul>
<li>Anonymous classes extending <code>ThreadLocal</code> which have an <code>initialValue()</code> method (can be replaced with <code>ThreadLocal.withInitial</code>)</li>
<li>Anonymous classes extending <code>Thread</code> which have a <code>run()</code> method (can be replaced with <code>new Thread(Runnable)</code></li>
</ul>
<p>Example:</p>
<pre><code>
<b>new</b> Thread() {
@Override
<b>public void</b> run() {
System.out.println("Hello from thread!");
}
}.start();
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
<b>new</b> Thread(() -> {
System.out.println("Hello from thread!");
}).start();
</code></pre>
<!-- tooltip end -->
</body>
</html>