Given this Scala code:
object test {
def byval(a: Int) = println("Int")
def byval(a: Long) = println("Long")
def byname(a: => Int) = println("=> Int")
def byname(a: => Long) = println("=> Long")
def main(args: Array[String]) {
byval(5)
byname(5)
}
}
the call byval(5) compiles correctly, but byname fails to compile:
ambiguous reference to overloaded definition
Why? I would expect to observe the same behavior for by-value and by-name parameters with respect to overloading… How can it be fixed?