title: Method reference is ambiguous for Thread.sleep
body: <p>I've come across a weird problem where a method reference to <code>Thread::sleep</code> is ambiguous but a method with the same signature is not.</p>
  
  <pre><code>package test;    
  
  public class Test
  {
      public static void main(String[] args)
      {
          foo(Test::sleep, 1000L); //fine
          foo((FooVoid&lt;Long&gt;)Thread::sleep, 1000L); //fine
          foo(Thread::sleep, 1000L); //error
      }
  
      public static void sleep(long millis) throws InterruptedException
      {
          Thread.sleep(millis);
      }
  
      public static &lt;P, R&gt; void foo(Foo&lt;P, R&gt; function, P param) {}
  
      public static &lt;P&gt; void foo(FooVoid&lt;P&gt; function, P param) {}
  
      @FunctionalInterface
      public interface Foo&lt;P, R&gt; {
          R call(P param1) throws Exception;
      }
  
      @FunctionalInterface
      public interface FooVoid&lt;P&gt; {
          void call(P param1) throws Exception;
      }
  }
  </code></pre>
  
  <p>I get those 2 errors:</p>
  
  <pre><code>Error:(9, 17) java: reference to foo is ambiguous
    both method &lt;P,R&gt;foo(test.Test.Foo&lt;P,R&gt;,P) in test.Test and method &lt;P&gt;foo(test.Test.FooVoid&lt;P&gt;,P) in test.Test match
  
  Error:(9, 20) java: incompatible types: cannot infer type-variable(s) P,R
      (argument mismatch; bad return type in method reference
        void cannot be converted to R)
  </code></pre>
  
  <p>The only difference I see is that <code>Thread::sleep</code> is <code>native</code>. Does it change anything? I don't think the overload <code>Thread::sleep(long, int)</code> comes into play here. Why does it happen?</p>
  
  <p>EDIT: Using javac version 1.8.0_111</p>