我试图用新的关键字创建一个队列。我为可变队列和不可变队列做了这件事。
但是当我尝试使用不可变队列时,它给出了错误:
<console>:8: error: constructor Queue in class Queue cannot be accessed in object $iw
Access to protected constructor Queue not permitted because
enclosing class object $iw in object $iw is not a subclass of
class Queue in package immutable where target is defined
val a=new Queue[Int]()
^
scala> import scala.collection.immutable.Queue
import scala.collection.immutable.Queue
scala> val a=new Queue[Int]()
<console>:8: error: constructor Queue in class Queue cannot be accessed in object $iw
Access to protected constructor Queue not permitted because
enclosing class object $iw in object $iw is not a subclass of
class Queue in package immutable where target is defined
val a=new Queue[Int]()
但是当我用可变队列、不可变堆栈、可变堆栈尝试这段代码时......效果很好
scala> import scala.collection.mutable.Queue
import scala.collection.mutable.Queue
scala> val a=new Queue[Int]()
a: scala.collection.mutable.Queue[Int] = Queue()
scala> import scala.collection.immutable.Stack
import scala.collection.immutable.Stack
scala> val a=new Stack[Int]()
a: scala.collection.immutable.Stack[Int] = Stack()
scala> import scala.collection.mutable.Stack
import scala.collection.mutable.Stack
scala> val a=new Stack[Int]()
a: scala.collection.mutable.Stack[Int] = Stack()
谁能告诉我,为什么会这样???