title: Java anonymous generics
body: <p>When I do this, the compiler will complain. </p>
  
  <pre><code>  private Map&lt;String, T&gt; map = new LinkedHashMap&lt;&gt;(16, (float) 0.75, true) {
          @Override
          protected boolean removeEldestEntry(Map.Entry eldest) {
              return size() &gt; capacity;
          }
      };
  </code></pre>
  
  <p>But when I do these, the compiler will accept it.</p>
  
  <pre><code>private Map&lt;String, T&gt; map = new LinkedHashMap(16, (float) 0.75, true) {
      @Override
      protected boolean removeEldestEntry(Map.Entry eldest) {
          return size() &gt; capacity;
      }
  };
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>   private Map&lt;String, T&gt; map = new LinkedHashMap&lt;String, T&gt;(16, (float) 0.75, true) {
          @Override
          protected boolean removeEldestEntry(Map.Entry eldest) {
              return size() &gt; capacity;
          }
      };
  </code></pre>
  
  <p>The entire code:</p>
  
  <pre><code>public class LRUCache&lt;T&gt; {
  
      private int capacity;
  
      private Map&lt;String, T&gt; map = new LinkedHashMap&lt;String, T&gt;(16, (float) 0.75, true) {
          @Override
          protected boolean removeEldestEntry(Map.Entry eldest) {
              return size() &gt; capacity;
          }
      };
  
  
  }
  </code></pre>
  
  <p>I know it may be something related to erasure. But I'm confusing about the details.</p>