有没有办法指定我想应用eta 扩展的方法的签名?
例如:
val tupleNum = (1L,2L)
case class CaseClass(a:String, b:String)
object CaseClass {
def apply(a: Long, b: Long): CaseClass = new CaseClass(s"${a}", s"${b}")
}
println( (CaseClass.apply _).tupled(tupleNum) )
抛出编译错误:
Error:(9, 29) ambiguous reference to overloaded definition,
both method apply in object CaseClass of type (a: String, b: String)CaseClass
and method apply in object CaseClass of type (a: Long, b: Long)CaseClass
match expected type ?
println( (CaseClass.apply _).tupled(tupleNum) )
顺便说一句:eta 扩展是使用_的正确术语吗?