我正在尝试在 Scala 中执行以下代码。
implicit def str2Int(x:String):Int = x.toInt
但我收到错误
Solution.scala:37: error: type mismatch;
found : x.type (with underlying type String)
required: ?{def toInt: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method augmentString in object Predef of type (x: String): scala.collection.StringOps
and method str2Int in object Result of type (x: String): Int
are possible conversion functions from x.type to ?{def toInt: ?}
implicit def str2Int(x:String):Int = x.toInt
^
Solution.scala:37: error: value toInt is not a member of String
implicit def str2Int(x:String):Int = x.toInt
我不知道这里出了什么问题。请提出建议。