作业帮 > 综合 > 作业

按scala的教程做一个队列的例子,

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/07/04 20:23:32
按scala的教程做一个队列的例子,
Error:(330,21) constructor Queue in class Queue cannot be accessed in class hello
Access to protected constructor Queue not permitted because
enclosing class hello is not a subclass of
class Queue in package immutable where target is defined
val empty = new Queue[Int]()
^
按scala的教程做一个队列的例子,
scala中Queue的声明是这样的:
class Queue[+A] protected(protected val in: List[A], protected val out: List[A])
         extends AbstractSeq[A]
            with LinearSeq[A]
            with GenericTraversableTemplate[A, Queue]
            with LinearSeqLike[A, Queue[A]]
            with Serializable {
 .
}

所以可以看出它的构造函数式protected的,因此你不能使用new访问它的构造函数.
不过你可以使用它的伴生对象来生成一个Queue的实例:
val empty = Queue[Int]()