It seems you can not initialize an Array with a SAM syntax. When I try the following...
trait A {
def num(): Int
}
trait B extends A
trait C extends A
val nums: Array[A] = Array(() => 5)
I get the following error...
<console>:12: error: type mismatch;
found : () => Int
required: A
val nums: Array[A] = Array(() => 5)
Is this behavior expected?
It works in Scala 2.12, but SAM support in Scala 2.11 is incomplete (that's why it's under
-Xexperimental). For Scala 2.11 you can useas a workaround.