title: Optional using a generic wild card in map and orElseGet
body: <p>I prepare a little example to replicate what happens in my project. I know how to workaround it, but I am very curious why it doesn't even compile. The problem is in the last return when I am using a generic wild card in the method <code>public TestElement&lt;?&gt; test()</code>, exactly the line <code>return response.map((element) -&gt; mapAux(50L)).orElseGet(()-&gt; orElseGetAux(20));</code>... I don't know why it doesn't compile. What am I doing wrong? Any clue?</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>public class FullTest {
    public static class TestElement&lt;T&gt;{
      public T element;
  
      public TestElement(T t) {
        element = t;
      }
    }
  
    public static &lt;U&gt; TestElement&lt;U&gt; createElement(U input) {
      return new TestElement&lt;&gt;(input);
    }
  
    private TestElement&lt;?&gt; mapAux(Long element){
      return new TestElement&lt;&gt;(element);
    }
  
    private TestElement&lt;?&gt; orElseGetAux(Integer element){
      return new TestElement&lt;&gt;(element);
    }
  
    public TestElement&lt;?&gt; test(){
      Optional&lt;Long&gt; response =  Optional.of(5L);
      return response.map((element) -&gt; mapAux(50L)).orElseGet(()-&gt; orElseGetAux(20));
    }
  }
  </code></pre>
  
  <p><strong>Update 1 - Include the error</strong></p>
  
  <p>I am using Java 8, over the last version of IntelliJ, and the error is this:</p>
  
  <blockquote>
    <p>Error:(33, 78) java: incompatible types: bad return type in lambda  expression</p>
  </blockquote>
  
  <pre><code>FullTest.TestElement&lt;capture#1 of ?&gt; cannot be converted to FullTest.TestElement&lt;capture#2&gt; of ?&gt;
  </code></pre>
  
  <p><strong>Update 2 - A little further and workaround</strong></p>
  
  <p>The use of wild card is because I need to return <code>TesElement&lt;&gt;</code> of different classes and It is the only way that I find out (in the example Long and Integer). I am open to other options...</p>
  
  <p>Here a possible workaround that I prefer avoid (It is an example, I know <code>isPresent()</code> always return true) :</p>
  
  <pre><code>public TestElement&lt;?&gt; testWorkAround(){
      Optional&lt;Long&gt; response =  Optional.of(5L);
      TestElement&lt;?&gt; testElement;
      if(response.isPresent()){
        testElement = mapAux(response.get());
      }
      else{
        testElement = orElseGetAux(20);
      }
      return testElement;
    }
  </code></pre>