Is there a way to create my own dynamic List with out using mutableListOf()? Cause in c++ we use pointers, while in Kotlin i think we cant :(
I searched in diferents sites and i only found how to use the function, not how was it created :(
Is there a way to create my own dynamic List with out using mutableListOf()? Cause in c++ we use pointers, while in Kotlin i think we cant :(
I searched in diferents sites and i only found how to use the function, not how was it created :(
Copyright © 2021 Jogjafile Inc.
mutableListOf()is just a shorthand to create an instance ofMutableList, optionally passing some arguments that will be placed in the list upon creation. The 0-arg version of the function is extremely simple and creates anArrayList:You can of course just create instances of lists yourself, by simply instantiating some implementation of the
MutableListinterface. For instance, on the JVM, you can create an instance ofArrayListorLinkedListby simply calling their constructor:You can also define your own list implementation by creating a class that implements the
MutableListinterface:And then you would create instances of it by calling its constructor:
You cannot use pointer arithmetic in Kotlin (or other JVM languages), but you don't really have to.