Kotlin: Queue interface has no constructors

I am trying to instantiate an object Queue

using below code

var queue: Queue<Int> = Queue()

But I get this

There are no constructors in the Queue interface

I don't know what's going on, I found a link while searching.

But I don’t understand anything. Please, help.

+3


source to share


2 answers


Queue

is an interface . Thus, you cannot create an interface, you must implement it, or instantiate a class that implements it.



For example, you can do var queue: Queue<Int> = ArrayDeque<Int>()

. ArrayDeque implements Queue

.

+12


source


You are trying to instantiate an interface, but you are not using override methods for it. You should use something like this:

val queueA = LinkedList<Int>()
val queueB = PriorityQueue<Int>()

      



Also you can read more about queue implementations here

+3


source







All Articles