cushon / issues-import

0 stars 0 forks source link

Warn on overloads which become ambiguous in common Java 8 usage patterns #263

Open cushon opened 9 years ago

cushon commented 9 years ago

Original issue created by kevinb@google.com on 2014-09-11 at 04:12 PM


Consider:

class A { static B c(D d) { ... } B c(A a, D d) { ... } }

(I don't know whether it's even proper to call these "overloads" or not, but you get the idea.)

This is fine in Java 7 but poses a problem in Java 8. In, for example, a context which expects a BiFunction<A,D,B>, the method reference A::c will now be ambiguous. Whether javac gives an error or has a rule for which one to choose, it's not a good situation either way. It would be useful if compiling class A produced a warning.

I believe there is a similar case:

void foo(Runnable r); void foo(Callable<Bar> c);

I think there can be some calls (perhaps foo(() -> { doSomething(); }) ?) where the lambda could be successfully target-typed to match either overload, which is bad for the same reasons.

(Sorry as usual for being too rushed to get more accurate details atm.)

I would recommend producing this warning even when compiling for pre-Java8, for future-proofing.

cushon commented 9 years ago

Original comment posted by kevinb@google.com on 2014-09-15 at 07:10 PM


Whoops, the "static" is on the wrong method!