可能性の重複:
How can I chain implicits in Scala?Scalaは1つの式で複数の暗黙的な変換を適用できますか?
Scalaは一つの式に複数の暗黙の型変換を適用することはできますか?
case class Wrapper(s: String)
case class WrapperWrapper(w: Wrapper)
implicit def string2Wrapper(s: String) = Wrapper(s)
implicit def wrapper2WrapperWrapper(w: Wrapper) = WrapperWrapper(w)
// implicit conversation --> w = string2Wrapper("w")
val w: Wrapper = "w"
// implicit conversation --> ww = wrapper2WrapperWrapper(w)
val ww: WrapperWrapper = w
// does NOT compile!
// ideally --> sad = wrapper2WrapperWrapper(string2Wrapper("ww"))
val sad: WrapperWrapper = "ww"
最後の行で「ダブル」の変換作業を取得するにはどのような方法があります:
は、この単純な例を考えてみましょうか?
私のような別の暗黙的に定義することによって沿って物事を助けることができる:
implicit def string2WrapperWrapper(s:String) = wrapper2WrapperWrapper(s)
が、それは必要ありませんように思える...