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

问题描述:

按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]()
^
1个回答 分类:综合 2014-10-04

问题解答:

我来补答
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]()
 
 
展开全文阅读
剩余:2000