[英]view bounds are deprecated; use an implicit parameter instead
我最近升級到 Scala 2.13,現在被警告棄用。 我的 function 看起來像這樣:
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 中,您就可以在 Scala 中找到一個錯誤,稱為 -Xfuture下的視圖邊界的棄用警告。 在實現這一點時,但如果您沒有在SCALA 編譯器選項中使用-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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.