== Why is this an issue?

Java 8 introduced ``++ThreadLocal.withInitial++`` which is a simpler alternative to creating an anonymous inner class to initialise a ``++ThreadLocal++`` instance.


This rule raises an issue when a ``++ThreadLocal++`` anonymous inner class can be replaced by a call to ``++ThreadLocal.withInitial++``.


=== Noncompliant code example

[source,java]
----
ThreadLocal<List<String>> myThreadLocal =
    new ThreadLocal<List<String>>() { // Noncompliant
        @Override
        protected List<String> initialValue() {
            return new ArrayList<String>();
        }
    };
----


=== Compliant solution

[source,java]
----
ThreadLocal<List<String>> myThreadLocal = ThreadLocal.withInitial(ArrayList::new);
----


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Replace this anonymous class with a call to "ThreadLocal.withInitial".


=== Highlighting

ThreadLocal instance creation


endif::env-github,rspecator-view[]
