为什么我在添加伴生对象时不能使用 case class 的 "tupled"?
Why I can't use "tupled" of case class when I add companion object?
当我将伴生对象添加到我的案例时 class 我无法使用元组将参数作为元组传递。
case class Person(name:String, age:Int)
object Person {}
Person.tupled // Not works
错误:
Error:(7, 9) value tupled is not a member of object A$A6.this.Person
Person.tupled
^
有人可以解释这种行为吗?谢谢!
由于tupled
方法是Function2的方法,
您可以通过 val f: ((String, Int)) => Person = (Person.apply _).tupled
实现。
对于自动合成案例 class 伴生对象,tupled
继承自 FunctionN
。但是,您 明确地 告诉 Scala 您希望您的伴随对象 而不是 从 FunctionN
继承,因此,您没有得到 tupled
.
当我将伴生对象添加到我的案例时 class 我无法使用元组将参数作为元组传递。
case class Person(name:String, age:Int)
object Person {}
Person.tupled // Not works
错误:
Error:(7, 9) value tupled is not a member of object A$A6.this.Person
Person.tupled
^
有人可以解释这种行为吗?谢谢!
由于tupled
方法是Function2的方法,
您可以通过 val f: ((String, Int)) => Person = (Person.apply _).tupled
实现。
对于自动合成案例 class 伴生对象,tupled
继承自 FunctionN
。但是,您 明确地 告诉 Scala 您希望您的伴随对象 而不是 从 FunctionN
继承,因此,您没有得到 tupled
.