Possible Bug in javac resolving method references.

taichi sato ryushi at gmail.com
Sun Oct 5 10:57:12 UTC 2014


Hi, I wrote code the below.

https://gist.github.com/taichi/f676381bd148bd497106

javac says me below

src\example\Main.java:13: error: reference to of is ambiguous
Consumers.of(Main::exec);
         ^
  both method of(OutputStreamConsumer) in Consumers and method
of(WriterConsumer) in Consumers match
src\example\Main.java:13: error: method of in interface Consumers cannot be
applied to given types;
Consumers.of(Main::exec);
            ^
  required: OutputStreamConsumer
  found: Main::exec
  reason: argument mismatch; invalid method reference
      no suitable method found for exec(Object,OutputStream)
          method Main.exec(Object) is not applicable
            (actual and formal argument lists differ in length)
          method Main.exec(Object,Appendable) is not applicable
            (argument mismatch; OutputStream cannot be converted to
Appendable)
2 errors

i think this is bug because eclipse jdt compiler can compile the code and

* first exec method has return type and one argument,
  OutputStreamConsumer and WriterConsumer require 2 argument and no return
value
  so this is not ambiguous. i think  compiler should pick a second exec
method.
* OutputStreamConsumer receives OutputStream, not Appendable.
   so compiler should pick WriterConsumer

my envrionment is below

* javac 1.8.0_20
* eclipse 4.4.0

thanks

Taichi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20141005/68caa113/attachment.html>


More information about the compiler-dev mailing list