https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

Robert

12/29/2018, 9:12 PM
I try to implement
LinkedList<E>
(from Java), but what Kotlin list should I extend?
ArrayList
is final, so can't use that, and just
List
makes me implement every method myself 😞 extending
MutableList
is even worse....
d

Dominaezzz

12/29/2018, 9:47 PM
AbstractList
?
1
r

Robert

12/29/2018, 11:19 PM
Thank you! That's what I was looking for. Now it forces me to implement
get(index: Int)
(and for mutable list a few more). Where do I get/save those values? Just create another list in a property of it?
d

Dominaezzz

12/29/2018, 11:28 PM
What values? (Also, I recommend extending
AbstractCollection
for a linked list).
r

Robert

12/29/2018, 11:32 PM
The values for the list....
It wants me to implement
get(index)
, what should I return....
d

Dominaezzz

12/29/2018, 11:58 PM
Return the element at that index in the list.
r

Robert

12/30/2018, 12:49 AM
Obviously, but how to get that, as I can't use
this.get(index)
as that's the method I am implement, where is the data stored?
d

Dico

12/30/2018, 1:18 AM
You need to implement that part, you decide
Consider extending
AbstractMutableList
, it will make more sense because you'll need to implement
add
and stuff.
You should not forget to override
iterator
as otherwise your iterator will be extremely slow, something like O(n2/2)
r

Robert

12/30/2018, 8:53 AM
But to save the data, I have to implement another list right? But eventually there has to be a list that saves data by itself instead of wrapping another list. Wonder how this list saves its data
d

Dico

12/30/2018, 8:58 AM
Look at the source for
java.util.LinkedList
k

kpgalligan

12/30/2018, 6:15 PM
You can use in native, but it’s designed to work multithreaded. Performance was not a huge concern
👌 1
4 Views