下面的Scala代码编译罚款:为什么我不能重用“不应用”不重复的方法签名
val f = (input: String) => Some("result")
object Extract {
def unapply(input: String): Option[String] = f(input)
}
val Extract(result) = "a string"
但是,如果我通过更换提取:
object Extract {
def unapply = f
}
然后编译失败:
error: an unapply result must have a member `def isEmpty: Boolean
val Extract(result) = "a string"
^
为什么? def isEmpty: Boolean
从哪里来?
我想,我们中的一些人只是喜欢嵌套...如果是Seq [Seq [Seq [Seq [Seq [Int]]]]? – Dima