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

标签 scala scala-2.8 iterable

我看到了这个话题:

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) => Any 的类型参数与类型 CC 的预期参数不匹配:没有类型参数,但类型 CC 有一个
  • 创建对象是不可能的,因为
    trait IterableLike 中的方法迭代器
    类型 => Iterator[java.io.File] 是
    未定义
  • 创建对象是不可能的,因为
    trait IterableLike 中的方法迭代器
    类型 => Iterator[V] 未定义
  • 覆盖 trait 中的方法元素
    IterableLike 类型 =>
    迭代器[java.io.File];方法
    元素需要`override'修饰符
  • 覆盖 trait 中的方法元素
    IterableLike 类型 => Iterator[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
          }
        }
      }
    }
    

    最佳答案

    前者elements现在是 iterator .

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

    关于scala - 将新的 Iterable{} 代码从 Scala 2.7.7 移植到 2.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3444748/

    相关文章:

    java - 对类型 `List<Iterable<Object>>` 的列表进行排序

    斯卡拉 2.8 : _ behaviour changed?

    scala - 如何从打包中排除不必要的非托管依赖项?

    scala - 没有给出变量时如何确定其类型?

    scala - `implicit' 修饰符不能用于顶级对象

    Scala 从函数返回元组

    scala - 从 scala 2.8.1 到 scala 2.9.1 的主要变化是什么?

    python - Python 的可迭代对象是否真的将所有值都存储在内存中?

    python-3.x - 为什么链接可迭代对象这么复杂?简化这段代码

    scala - 如何在 Scala 中的语句之间等待 N 秒?