我正在尝试使用 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
._
编辑:
至于 FromRepr
和 HasElem
,我在 package 中找不到它们。 。另外,在阅读了 Miles Sabin 对 How 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/