title: Why is this Java generic method call ambiguous when only one method is valid when separate?
body: <p>I am trying to understand why the compiler is unable to resolve the <code>bar</code> method call. I would expect <code>bar(Xyz::new)</code> to always select <code>bar(Supplier)</code> as <code>bar(T extends Xyz)</code> can never match due to the upper bound on <code>Xyz</code>.</p>
  <pre class="lang-java prettyprint-override"><code>public &lt;T extends Xyz&gt; void foo(T s) {}
  public &lt;T extends Xyz&gt; void bar(T s) {}
  public &lt;T extends Xyz&gt; void bar(Supplier&lt;T&gt; s) {}
  
  public void example() {
      foo(Xyz::new); // not valid (does not extend Xyz)
  
      bar((Supplier&lt;Xyz&gt;) Xyz::new); // valid (explicitly a Supplier)
      bar(Xyz::new); // ambiguous - but only one method is valid?
  }
  
  public static class Xyz {}
  </code></pre>
  <p>If <code>bar(T)</code> is not applicable, even when alone (as shown with <code>foo(T)</code>), then surely the only option is <code>bar(Supplier)</code> making this a non-ambiguous overload.</p>
  <p>Why is the <code>bar</code> call ambiguous, especially when the <code>foo</code> and <code>bar(T)</code> calls are not valid resolutions themselves?</p>
  <p>Runnable example of above code: <a href="https://www.jdoodle.com/ia/kqP" rel="noreferrer">https://www.jdoodle.com/ia/kqP</a></p>