![]() ![]() Sure, bad Java mutable data structures should not be reproduced. On the contrary, it may be the worst thing to do with a linked list, depending upon how it is implemented. And no, fast injection of elements inside the list is not the only thing LinkedList is good for. In my opinion, using “non modifiable” lists as if they where immutable, or using mutable lists when you need immutable ones, is far more dangerous than using immutable, data sharing, linked lists, specifically if the “dangerous” operations have not been implemented on them. How should we do it? Should we use a mutable list? But what if we need to share the list? Or simply reuse it later? Should we make defensive copies? Adding an element in front of a “non-modifiable” list is painful and inefficient. They are easy to implement, but it would be better if they were standard, since they are much better for some use cases than what Kotlin offers. Immutable linked lists are missing in Kotlin. They are not for accessing elements by index or for some bulk operations like reversing. Linked lists are extremely efficient for sequentially accessing elements from one end or for adding elements to one end. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |