title: Compiler not inferring System.out::println functional interface
body: <p>I have an overloaded method that takes two different functional interfaces as parameters (<code>Runnble</code> and <code>Supplier</code>). <code>System.out.println</code> is clearly only compatible with <code>Runnable</code>, because it is a <code>void</code> method. Yet the compiler still claims that the call is ambiguous. How is that possible?</p>
  
  <pre><code>import java.util.function.Supplier;
  
  public class GenericLambdas {
      public static void main(String[] args) {
          wrap(System.out::println);   // Compiler error here
          wrap(() -&gt; {});              // No error
          wrap(System.out::flush);     // No error
      }
  
      static &lt;R&gt; void wrap(Supplier&lt;R&gt; function) {}
  
      static void wrap(Runnable function) {}
  }
  </code></pre>
  
  <p>Compiler output:</p>
  
  <pre><code>Error:Error:line (5)java: reference to wrap is ambiguous
      both method &lt;R&gt;wrap(java.util.function.Supplier&lt;R&gt;) in GenericLambdas and method wrap(java.lang.Runnable) in GenericLambdas match 
  Error:Error:line (5)java: incompatible types: cannot infer type-variable(s) R
      (argument mismatch; bad return type in method reference
        void cannot be converted to R)
  </code></pre>
  
  <p>Based on the second error (<code>argument mismatch, void cannot be converted to R</code>), shouldn't the compiler be able to disambiguate the call? That would then take care of both compiler errors (as it will neither be ambiguous, nor will it try to convert void to R).</p>
  
  <p>And why are <code>() -&gt; {}</code> and <code>System.out::flush</code> able to resolve? They have the same signature as <code>System.out.println</code>. Granted that <code>System.out.println</code> is overloaded with versions that take an argument, but none of those overloaded versions match either <code>Supplier</code> or <code>Runnable</code>, so I don't see how they would be relevant here.</p>
  
  <h2>EDIT:</h2>
  
  <p>It seems that this <em>does</em> compile and run with the <a href="https://stackoverflow.com/questions/3061654/what-is-the-difference-between-javac-and-the-eclipse-compiler">Eclipse compiler</a>. Which compiler is correct, or is either behavior allowed?</p>