scala – 为什么Option扩展产品?
发布时间:2020-12-16 09:05:56 所属栏目:安全 来源:网络整理
导读:我必须遗漏一些东西,但我没有看到 Option 类中 Product 特性的productElement和productArity的实现. 所以有两个问题: 为什么Option会扩展产品? Option(或其中任何两个子类)没有实现这两种方法怎么样? 解决方法 在scala中生成Option时,实际上生成了Some或N
我必须遗漏一些东西,但我没有看到
Option 类中
Product 特性的productElement和productArity的实现.
所以有两个问题: >为什么Option会扩展产品? 解决方法
在scala中生成Option时,实际上生成了Some或None,它们都是case类/对象. scala编译器使用case类来实现它,并为它们生成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 */ 我希望能回答你的问题,编译魔术! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |