Consider the following piece of code:
case class User(id: Int, name: String)
object User{
def unapply(str: String) = Some(User(0, str))
}
Scala抱怨“错误:无法解析重载的unapply; case class User(id:Int,str:String)” 不能重载unapply吗? 更新: 使用更大的元组大小进行unapply。
case class User(id: Int, str: String)
object User{
def unapply(s: String) = Some((User(0, s), s, 1234))
}
编译器仍在抱怨“无法解析重载的unapply”。
object NameOfUser {def unapply(s: String): Option[User]...}
。我不知道在你的代码中是否有意义。 - Didier Dupont