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/

    相关文章:

    python - 测试某个值是否不是由迭代器产生的

    scala - Intellij 多模块 maven 项目,其中一个子模块中的更新不会传播到 war

    java - 避免多个 Singleton 实例?

    scala - scala 2.8 中的隐式转换问题

    python - 检查类是否可迭代

    python - 从 python 中成功的正则表达式匹配构建字典

    scala - 如何使用 orElse 组合返回 Option 的函数?

    scala - 在可变参数中使用惰性求值函数

    scala - 在其他长期运行的 Actor 在场的情况下,如何防止 Actor 饥饿?

    scala - 有没有办法在 scala 2.8 中创建一个 IdentityMap