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

Scala中预期的定义错误开始

发布时间:2020-12-16 18:21:02 所属栏目:安全 来源:网络整理
导读:我正在尝试运行 this math.stackexchange post中提供的Scala代码(请参阅第二个答案),但似乎遇到了以隐式def开头的行中的问题….编译器告诉我错误:预期的定义开始. 有什么想法吗?谢谢! 我应该补充说我正在使用http://www.tutorialspoint.com/compile_scala
我正在尝试运行 this math.stackexchange post中提供的Scala代码(请参阅第二个答案),但似乎遇到了以隐式def开头的行中的问题….编译器告诉我错误:预期的定义开始.

有什么想法吗?谢谢!

我应该补充说我正在使用http://www.tutorialspoint.com/compile_scala_online.php来运行我的代码.

解决方法

刚刚在Scala REPL上试过你的例子,它对我有用.

将隐式def移动到对象:

object MyImplicits {
  /** Pimp `Set[X]` with a few convenient operators */
  implicit def logicalSetOps[X](set: Set[X]) = new {
    def and(other: Set[X]) = set.intersect(other)
    def or(other: Set[X]) = set.union(other)
    def minus(other: Set[X]) = set.filterNot(other.contains)
  }
}

然后做:

import MyImplicits._

这对你有用.

(编辑:李大同)

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

    推荐文章
      热点阅读