scala - Scala 隐式函数
问题描述
我正在尝试在 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
我不知道这里有什么问题。请建议。
解决方案
推荐阅读
- python - 在 numpy ndarray 中找到两个最接近的值
- java - Java JDK 11 的安装不包括 rt.jar
- javascript - Javascript - 打破循环依赖的问题
- python-3.x - 如何处理python中的用户输入错误
- python - 为什么 Netmiko 不使用动态分配的(主机名)IP 地址进行连接?
- reactjs - 获取与给定 ID 不匹配的 Firestore 集合查询中的第一项
- .net-core - 如何在 Linux 上以后台模式执行 dotnet 测试
- python - 如何在发出 n 次请求后重新启动会话
- go - 为什么 O(n^2) 解决方案更快?2020 年代码出现的第 1 天
- python - 如何从网站上的图表中抓取值