Given this definition in Scala:
class Foo(val n: Int)
object Foo {
def unapply(foo: Foo): Option[Int] = Some(foo.n)
}
This expression compiles and returns ok:
new Foo(1) match {
case Foo() => "ok"
}
- Why does this even compile? I would expect that an extractor with
Option[T]implies matching patterns with exactly one argument only. - What does the pattern
Foo()mean here? Is it equivalent toFoo(_)?
In other words, what is the language rule that enables the experienced behavior.