加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 18:40:05 所属栏目:安全 来源:网络整理
导读:我看到了这个帖子: What are the biggest differences between Scala 2.8 and Scala 2.7? 它似乎涵盖了一些变化,但似乎没有提到我遇到的第一个编译问题.有什么建议? 类型参数的种类(Iterable [Any] with(A with Int)= Any)不符合类GenericCompanion中类型
我看到了这个帖子:

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的有用提示.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读