【发布时间】:2018-03-16 06:56:07
【问题描述】:
试图理解这种隐含发现的案例 - finding implicit of an argument's type。我将官方示例复制粘贴到 IDE 中,只是将方法名称更改为 mul,如下所示:
class A(val n: Int) {
def mul(other: A) = new A(n + other.n)
}
object A {
implicit def fromInt(n: Int) = new A(n)
}
1 mul (new A(1))
现在它会导致编译错误:
value mul is not a member of Int
我还尝试使用 String 而不是 Int 进行试验,这再次导致编译错误。
你能解释一下我做错了什么吗?
【问题讨论】:
标签: scala implicit-conversion implicit