私は何かが欠けているに違いありませんが、クラスの特性の実装productElementと特性がわかりません。productArityProductOption
したがって、2つの質問:
- なぜ
Option拡張するのでしょうProductか? - (またはその
Option2つのサブクラスのいずれかが)2つのメソッドを実装していないのはどうしてですか?
Optionin scala を生成すると、実際には両方ともケース クラス/オブジェクトであるaSomeまたは aが生成されます。Nonescala コンパイラは、ケース クラスで魔法のように動作しProduct、それらのメソッドを生成します。
Scala 2.10 Product.scala から:
/** Base trait for all products, which in the standard library include at
* least [[scala.Product1]] through [[scala.Product22]] and therefore also
* their subclasses [[scala.Tuple1]] through [[scala.Tuple22]]. In addition,
* all case classes implement `Product` with synthetically generated methods.
*
* @author Burak Emir
* @version 1.0
* @since 2.3
*/
コンパイラの魔法、両方の質問に答えてくれることを願っています!