我正在尝试执行以下代码:
def sum(e: { def *(x: Double): Double}) = e * 2.0
问题是,这不适用于任何数字类:
sum(20.0)
<console>:9: error: type mismatch;
found : Double(10.0)
required: AnyRef{def *(x: Double): Double}
algo(10.0)
sum(10)
<console>:9: error: type mismatch;
found : Int(10)
required: AnyRef{def *(x: Double): Double}
algo(10)
我的代码有问题吗?