本質的に、 val と def の微妙な違いに似た質問です。メンバーシングルトンオブジェクトを持つことの意味的な違いは何だろうか:
class Text {
...
object Whitespace { def unapply(s :String) =
if (s.forall(_.isWhitespace)) Some(s) else None
}
}
と
class Text {
...
val Whitespace = new { def unapply(s :String) =
if (s.forall(_.isWhitespace)) Some(s) else None
}
}
どちらもバイトコードに変換する方法は知っていますが、一方のコードではできないことで、もう一方のコードでは何ができるのでしょうか?