Consider the following Scala code.
object Q{
trait C{
def f(x: Int) : Int
}
def applyTo3(c: C) = c.f(3)
def main(args: Array[String]) = println(applyTo3(x => x+1))
}
This looks like it shouldn't compile: the function applyTo3
expects an argument of type C
, but instead is given an argument of type Int => Int
. But in fact it does compile, and gives the result 4 when run. The function is somehow being converted to an object of type C
, but I don't see how.
Gavin