以下代码无法编译,因为两个乘法运算符 have same type after erasure : (f: Object)Object
我知道类型擦除,但我看到的所有情况都删除了 generic 类型,如 List[Int]
或 List[String]
,如Scala double definition (2 methods have the same type erasure)中所述 .
如何让Scala对待不同类型的XxxT`类型不同?
trait AbstractTypes {
type ScalarT
type VectorT
abstract class Operators(u: VectorT) {
def *(f: ScalarT): VectorT
def *(v: VectorT): VectorT
}
}
2 回答
这就是DummyImplicit的用途:
如果需要更多重载次数相同的重载,则可以包含任意数量的
DummyImplicit
.使用answer中的一个技巧来处理链接的问题(将seconds方法的参数声明为call-by-name):