Stephan Schroeder
10/15/2019, 1:19 PMArtyom Degtyarev [JB]
10/15/2019, 1:21 PMserebit
10/15/2019, 1:21 PMList
in the standard library merely obscures the methods of modifying the data in the list.Dias
10/15/2019, 1:22 PMAlternative:
Use mutable collections, but once they are populated expose them only though their read-only interfaces. This pattern is mostly used in the standard library collection operations.
Pro: mutable collection implementations are generally more memory efficient, require less allocations during and after their populating.
Con: collection can be cast back to mutable (e.g. involving platform types), and then unexpectedly mutated.
Con: different snapshots of a collection do not share any element storage.
Con: defensive copying of the resulting collection is still required later in a chain of operations.
Con: mutable collections need safe publication to share them to a different thread.
Marko Mitic
10/15/2019, 1:22 PMStephan Schroeder
10/15/2019, 2:43 PM