【发布时间】:2011-03-27 13:30:23
【问题描述】:
我看到了这个帖子:
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 有一个
- 无法创建对象,因为 特征 IterableLike 中的方法迭代器 类型 => Iterator[java.io.File] 是 未定义
- 无法创建对象,因为 特征 IterableLike 中的方法迭代器 类型 => Iterator[V] 未定义
- 覆盖特征中的方法元素 IterableLike 类型 => 迭代器[java.io.File];方法 元素需要 `override' 修饰符
- 覆盖特征中的方法元素 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
}
}
}
}
【问题讨论】:
-
提供了文件的导入和
iterator的全局替换elements,您的代码编译。