Scala:编译器找不到 FromRepr、HasElem 或implicitConversions

标签 scala scala-collections

我正在尝试使用 Miles Sabins 对 How do I apply the enrich-my-library pattern to Scala collections? 的回答来拉皮条 TraversableLike但是编译器无法识别 FromRepr、HasElem 或implicitConversions

package packMain
import scala.collection.generic.{ CanBuildFrom, FromRepr, HasElem }
import language.implicitConversions

class ImplClasses {}

FromRepr is not a member of scala.collection.generic
HasElem is not a member of scala.collection.generic
not found object language

我尝试使用带有 Scala 插件 2.02 和 2.9.2 Final 的 Eclipse Indigo 以及带有 Scala 插件 2.1M2 和 2.10.0M7 的 Eclipse 4.2 Juno 编辑:

import language.implicitConversions._ //works in 2.10M7 as gilad hock's comment
import scala.collection.generic.FromRepr._ //object FromRep is not a member of ...
import scala.collection.generic.HasElem._ //object HasElem is not a member of ...

最佳答案

要使隐式工作,您需要显式导入它们,而不仅仅是包含包。您可以使用通配符:import language.implicitConversions._

编辑:
至于 FromReprHasElem,我在 package 中找不到它们。 。另外,在阅读了 Miles SabinHow do I apply the pimp-my-library pattern to Scala collections? 的回答后,我注意到他说:截至 this commit这更容易...这告诉我它还不是 scala 库的一个组成部分(还?),否则,他可能会链接到包定义,而不是 github 上的某个提交。这样您就可以克隆并从源代码构建自己。

关于Scala:编译器找不到 FromRepr、HasElem 或implicitConversions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12482188/

相关文章:

scala - 在不计算的情况下获取 Spark 数据帧中的行数

scala - 如何使用 Play 2.0 定义标签?

使用phantm扫描PHP项目时出现Java错误

scala - 可变 Scala 集合的不可修改 View

scala - 如何设置 Scala 2.10 并行集合的默认线程数?

scala - 基本 Scalaz 状态问题

scala - 播放框架 : how to not watch a folder for changes in Play Framework

Scala Sets 包含相同的元素,但 SameElements() 返回 false

scala Iterable#map 与 Iterable#flatMap

scala - 是否有 Guava MultiSet 和 Table 概念的 Scala 替代品?