Closed
Description
Compiler version
3.0.0-RC1
EDIT: happens on latest master
as well.
Minimized code
import java.util.function.Function
class Future[T](val initial: T) {
def map[V](v: V): Unit = println(v)
def map[U](fn: Function[T, U]): Unit = println(fn(initial))
}
val f = new Future(42)
val fn = (i: Int) => i.toString
f.map(fn)
Output
main$package$$$Lambda$50530/134842729@268fb089
(does not matter if using def or lambda syntax)
Expectation
In Scala 2, the same code will not compile . It reports:
type mismatch;
found : Int => String
required: java.util.function.Function[Int,?]
Vertx's Future has two such map methods, for example. As a feature request, it would be very nice to have special handling for java.util.function
interfaces so f.map(fn: Function[Int, String])
is not required.