I have already checked, but just to be sure, allow...
# getting-started
x
I have already checked, but just to be sure, allow me to ask: is there an immutable deque in Kotlin. There's ArrayDeque but it is not immutable. I am using LinkedBlockingDeque (a java implementation), but want to replace it with an immutable one.
s
Given that the point of using a specialised queue implementation (over, say, a regular ArrayList) is efficient enqueue and dequeue operations (i.e. mutations), would there be much point to an immutable deque? Could you just use an immutable list?
🙏 1
x
@Sam You're right, I'll just use the immutable list. Thanks
🐕 1
k
I've just looked through documentation and got confused. In Kotlin,
ArrayDeque
implements
MutableList
(and therefore also
List
). But in Java,
ArrayDeque
implements
Deque
and
Queue
but not
List
. That sounds like a problem if a Java method calls a method that it expects to return a List. If the called method is written in Kotlin, it can return an
ArrayDeque
(because that's a
List
in Kotlin) but when Java gets it, it won't be a Java
List
.
s
@Klitos Kyriacou that’s okay because the Java
ArrayDeque
and the Kotlin
ArrayDeque
are actually two separate classes. They’re not aliases for one another like
ArrayList
would be.
👍 1
x
@Klitos Kyriacou The java ArrayDeque is identified as "java.util.ArrayDeque", while the kotlin one is "kotlin.collection.ArrayDeque", so there shouldn't be any error
👍 1
e
I can see where the confusion may come from, given that
kotlin.collections.ArrayList == java.util.ArrayList
etc., but there's only a limited number of types for which that aliasing takes place
👍 1
j
and kotlin ArrayDeque is a fairly recent addition. If you're working toy problems in hacckerrank or leetcode its not going to be available
e
since 1.4, released August 2020. I don't think that's very recent by Kotlin standards; hackerrank and leetcode are just outrageously outdated
m
codewars also works with old stuff for kotlin which constantly annoys me