微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将新的Iterable {}代码从Scala 2.7.7移植到2.8

我看到了这个帖子:

What are the biggest differences between Scala 2.8 and Scala 2.7?

它似乎涵盖了一些变化,但似乎没有提到我遇到的第一个编译问题.有什么建议?

>类型参数的种类(Iterable [Any] with(A with Int)=> Any)不符合类GenericCompanion中类型参数(类型CC)的预期种类. Iterable [Any] with(A with Int)=>任何类型参数都不匹配CC类型的预期参数:没有类型参数,但类型CC有一个
>对象创建不可能,因为
trait中的方法迭代器IterableLike
of type => Iterator [java.io.File]是
没有定义的
>对象创建不可能,因为
trait中的方法迭代器IterableLike
of type =>迭代器[V]未定义
>重写特征中的方法元素
IterableLike of type =>
迭代器[java.io.File的];方法
元素需要`覆盖’修饰符
>重写特征中的方法元素
IterableLike of type =>迭代器[V];
方法元素需要`覆盖’
修改

这是有问题的代码

/**
 * Filesystem walker.
 * <p>
 * Less magic version of: http://rosettacode.org/wiki/Walk_Directory_Tree#Scala
 */
object FsWalker {
  /**
   * Recursive iterator over all files (and directories) in given directory.
   */
  def walk(f: File): Iterable[File] = new Iterable[File] {
    def elements = {
      if (f.isDirectory()) {
        // recurse on our child files
        f.listFiles.elements.flatMap(child => FsWalker.walk(child).elements)
      } else {
        // just return given file wrapped in Iterator
        Seq(f).elements
      }
    }
  }
}

解决方法

前面的元素现在是迭代器.

您应该使用-Xmigration进行编译,以获取有关如何将代码从2.7移植到2.8的有用提示.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐