title: Custom collector not compile
body: <p>I'm creating a custom Collector but it is failing when using it while compiling.</p>
  <pre><code> private static &lt;T&gt; Collector&lt;T, ?, T&gt; getFirstElement() {
      return Collectors.collectingAndThen(
          Collectors.toList(),
          list -&gt; {
              if (list.size() == 0) {
                  return null;
              }
              if (list.size() &gt; 1) {
                  log.info(&quot;There are more than 1 registry&quot;);
              }
              return list.get(0);
          }
      );
  } 
  
  
  String myString = &quot;test&quot;;
  Optional.of(myString)
     .map(myService::getFromDatabase)
     .collect(getFirstElement());
  </code></pre>
  <p>myService.getFromDatabase(string) return a list of Items.</p>
  <p>I receive an error while compiling</p>
  <pre><code>cannot find symbol
  [ERROR]   symbol:   method collect(java.util.stream.Collector&lt;java.lang.Object,capture#1 of ?,java.lang.Object&gt;)
  [ERROR]   location: class java.util.Optional&lt;java.util.List&lt;com.package.Item&gt;&gt;
  </code></pre>
  <p>Why am I having this error?</p>