scala - 视图边界已弃用;改用隐式参数
问题描述
我最近升级到 Scala 2.13,现在被警告弃用。我的功能如下所示:
implicit def convertGeneralResult[A <% ToResponseMarshallable, B <% ToResponseMarshallable](r: Either[A, B]) =
r.fold[ToResponseMarshallable](identity, identity)
弃用警告显示(我实际上有两个,每个类型参数 A/B 一个):
视图边界已弃用;改用隐式参数。
示例:而不是def f[A <% Int](a: A)
使用def f[A](a: A)(implicit ev: A => Int)
不过,我不完全确定如何在我的情况下应用建议的修复程序。
解决方案
这个问题有很多深度,但我只会提供一些参考,以防你想深入研究它,以及如何解决它。
早在 2013 年,在 Scala 2.11 中,您就可以在 -Xfuture 下找到一个名为 deprecation warning for view bounds的 Scala 错误。在实现这一点时,但如果您没有使用SCALA COMPILER OPTIONS-Xfuture
中的选项,您就不知道这一点。
在 2018 年,没有 -Xfuture 的弃用视图边界被打开,如您所见,它已合并到 Scala 2.13中。
作为另一个参考,有一个类似的问题Scala 2.13.0 deprecates <%, but how do I get rid of this in a class definition。
现在到你的问题。您需要做的就是删除<%
用法,并将其替换为隐式:
implicit def convertGeneralResult[A, B](r: Either[A, B])(implicit aToMarshallable: A => ToResponseMarshallable, bToMarshallable: B => ToResponseMarshallable) =
r.fold[ToResponseMarshallable](identity, identity)
推荐阅读
- javascript - 反应Js | 无法读取未定义的属性“道具”
- javascript - Cucumber-JS 中的可选参数
- c# - 日期格式识别
- mp4 - 检测 h264 流中的 I 帧(分段 mp4)
- qlikview - 我想加载 2 个相同且来自相同源 QVD 的表,但其中一个我执行循环
- handlebars.js - 有没有办法在 schema.org 微数据中排除文本被读取?
- python - 如何将 xmlTree iterparse 应用于嵌套的 XML 集
- odata - 如何使用 Sitefinity oData(Web 服务)获取内容项的完整内容 URL 并将其添加到响应数据中?
- python - 绘制自定义图形 python
- reactjs - Typescript 在 VSCode 导入时自动添加 ~/ 而不是 ../../