加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 为什么不设置实现PartialFunction?

发布时间:2020-12-16 10:07:48 所属栏目:安全 来源:网络整理
导读:Scala编程:综合循序渐进指南,第2版,第546页: In the inheritance hierarchy below Iterable you find three traits: Seq, Set,and Map. A common aspect of these three traits is that they all implement the PartialFunction trait with its apply and
Scala编程:综合循序渐进指南,第2版,第546页:

In the inheritance hierarchy below Iterable you find three traits: Seq,
Set,and Map. A common aspect of these three traits is that they all
implement the PartialFunction trait with its apply and isDefinedAt
methods.

但是,此代码无法编译(尝试2.8.2和2.10.2):

Set(1,2,3).isDefinedAt(1)

有错误:

value isDefinedAt is not a member of scala.collection.immutable.Set[Int]

这是书中的错误吗?

解决方法

当然看起来像.走到Scala 2.5.0:

> SeqMap扩展PartialFunction:
> Set没有.

这似乎是明智的:设置从对象到布尔值的映射,因此它始终定义(成员为true,非成员为false).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读