![](/img/trans.png)
[英]Could not find implicit value for parameter lgen: shapeless.LabelledGeneric.Aux
[英]Scala type parameterization, Shapeless - could not find implicit value for parameter Generic
我無法實現shapeless.Generic與Scala類型的參數化函數。 在以下代碼中,我收到錯誤消息“找不到參數gen的隱式值:shapeless.Generic [T]”。
def foo[T](instance: T) = {
val gen = shapeless.Generic[T] //getting error in this line!!!
val values = gen.to(instance)
println(values)
}
case class Bar(x:String, y:String)
var bar = Bar("a","b")
foo(bar)
我有什么想念的嗎?
def foo[T, HL <: HList](instance: T)(
implicit gen: Generic.Aux[T, HL]
) = {
val values = gen to instance
println(values)
}
case class Bar(x: String, y: String)
通常,您需要使用Aux
模式,泛型是宏實現的,但是會產生一個暴露為抽象類型成員的任意類型。 如果您現在還聽不懂所有單詞,請在此處閱讀更多內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.