在Scala中实现文件系统类结构的合适方法是什么?
我希望Root
成为Directory
并以自己为父母。
import scala.collection.mutable
sealed trait Entry
class Directory(val parent: Directory, val content: mutable.IndexedSeq[Entry]) extends Entry
class File(val parent: Directory, val content: String) extends Entry
object Root extends Directory(Root, mutable.IndexedSeq[Entry]())
以上尝试导致:
错误:
(23,31)超级构造函数无法传递自引用,除非 参数由名称对象声明根扩展目录(Root,IndexedSeq())