10

Considering

object A {
  def m(i: Int) = i
  val m = (i: Int) => i * 2
}

one gets

scala> A.m(2)
<console>: error: ambiguous reference to overloaded definition,
both value m in object A of type => (Int) => Int
and  method m in object A of type (i: Int)Int
match argument types (Int)
       A.m(2)
         ^

Accessing the val can be done with

scala> val fun = A.m
fun: (Int) => Int = <function1>

scala> fun(2)
res: Int = 4

or

scala> A.m.apply(2)
res: Int = 4

but how would one access the def?

Debilski
  • 66,976
  • 12
  • 110
  • 133

1 Answers1

11

It is total rubbish (please, don't do this at home), but you can do it by assigning A to a variable of structural type, that has only the first m.

val x : { def m(i:Int):Int } = A
x.m(10)
jpalecek
  • 47,058
  • 7
  • 102
  • 144