我用無形的情況下級轉化, 我有2例類:不成形的情況下級轉化
import shapeless._
case class Foo(id: Int, name: String)
case class Bar(id: Int, name: String, price: Double)
val fooGen = Generic[Foo]
val barGen = Generic[Bar]
val foo = Foo(1, "foo")
val fooRepr = fooGen.to(foo)
val additional = fooRepr :+ 1.0
val bar = barGen.from(additional)
這工作得很好,但是當我嘗試轉換酒吧爲foo
fooGen.from(barGen.to(bar))
我得到一個錯誤:
found : main.barGen.Repr
[error] (which expands to) shapeless.::[Int,shapeless.:: [String,shapeless.::[Double,shapeless.HNil]]]
[error] required: main.fooGen.Repr
[error] (which expands to) shapeless.::[Int,shapeless.::[String,shapeless.HNil]]
[error] println(fooGen.from(barGen.to(bar)))
是否有可能轉換一個案例類的地方比另一個更多?