私は何かが欠けているに違いありませんが、クラスの特性の実装productElement
と特性がわかりません。productArity
Product
Option
したがって、2つの質問:
- なぜ
Option
拡張するのでしょうProduct
か? - (またはその
Option
2つのサブクラスのいずれかが)2つのメソッドを実装していないのはどうしてですか?
Option
in scala を生成すると、実際には両方ともケース クラス/オブジェクトであるaSome
または aが生成されます。None
scala コンパイラは、ケース クラスで魔法のように動作し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
*/
コンパイラの魔法、両方の質問に答えてくれることを願っています!