3

私は何かが欠けているに違いありませんが、クラスの特性の実装productElementと特性がわかりません。productArityProductOption

したがって、2つの質問:

  1. なぜOption拡張するのでしょうProductか?
  2. (またはそのOption2つのサブクラスのいずれかが)2つのメソッドを実装していないのはどうしてですか?
4

1 に答える 1

7

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
 */

コンパイラの魔法、両方の質問に答えてくれることを願っています!

于 2013-03-12T22:12:40.303 に答える