按scala的教程做一个队列的例子,编译时候报错不知道是什么意思?
Error:(330,21)constructorQueueinclassQueuecannotbeaccessedinclasshelloAccesstoprotect...
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]()
^ 展开
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个回答
展开全部
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]()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询