我正在尝试向Symbol类添加更新方法.
class SymbolUpdate(s: Symbol) {
def update(i: Int) = s.name + i
}
implicit def toSymbolUpdate(s: Symbol) = new SymbolUpdate(s)
Run Code Online (Sandbox Code Playgroud)
但是当我运行代码时,我得到以下内容
scala> 's = 1
<console>:327: error: value update is not a member of object Symbol
's = 1
^
Run Code Online (Sandbox Code Playgroud)
但是当我直接调用该方法时它确实有效.
scala> 's.update(1)
res41: java.lang.String = s1
Run Code Online (Sandbox Code Playgroud)
或者,如果我显式地放置一个空参数数组.
scala> 's() = 1
res42: java.lang.String = s1
Run Code Online (Sandbox Code Playgroud)
不确定我的代码有什么问题?
scala ×1