gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:05:11 25 4
gpt4 key购买 nike

我看到了这个话题:

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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com