按scala的教程做一个队列的例子,Error:(330,21) constructor Queue in class Queue cannot be accessed in class helloAccess to protected constructor Queue not permitted becauseenclosing class hello is not a subclass of class Queue in package im
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/31 18:12:10
按scala的教程做一个队列的例子,Error:(330,21) constructor Queue in class Queue cannot be accessed in class helloAccess to protected constructor Queue not permitted becauseenclosing class hello is not a subclass of class Queue in package im
按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的教程做一个队列的例子,Error:(330,21) constructor Queue in class Queue cannot be accessed in class helloAccess to protected constructor Queue not permitted becauseenclosing class hello is not a subclass of class Queue in package im
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]()