我必须遗漏一些内容,但我看不到Product
课程中productElement
特征productArity
和Option
的实施情况。
所以有两个问题:
Product
会延长Option
?答案 0 :(得分:7)
在scala中生成Option
时,实际上生成的Some
或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
*/
我希望能回答你的问题,编译魔术!