immutablelist

How to create an immutable list in Kotlin that is also an immutable list in Java?

点点圈 提交于 2020-07-03 01:59:48
问题 I have a Java/Kotlin interop problem. A Kotlin immutable list is compiled into a normal java.util.ArrayList that is mutable! Kotlin (library): class A { val items: List<Item> = ArrayList() } Java (consumer): A a = new A(); a.getItems().add(new Item()); // Compiles and runs but I wish to fail or throw How to make my Kotlin class fully immutable from Java perspective too? 回答1: All non- Mutable____ collections in Kotlin are compile time read-only types by default, but not immutable . See the

How to create an immutable list in Kotlin that is also an immutable list in Java?

五迷三道 提交于 2020-07-03 01:59:32
问题 I have a Java/Kotlin interop problem. A Kotlin immutable list is compiled into a normal java.util.ArrayList that is mutable! Kotlin (library): class A { val items: List<Item> = ArrayList() } Java (consumer): A a = new A(); a.getItems().add(new Item()); // Compiles and runs but I wish to fail or throw How to make my Kotlin class fully immutable from Java perspective too? 回答1: All non- Mutable____ collections in Kotlin are compile time read-only types by default, but not immutable . See the

Slow performance from ImmutableList<T> Remove method in Microsoft.Bcl.Immutable

耗尽温柔 提交于 2019-12-21 17:17:14
问题 Experiencing some unexpected performance from Microsoft ImmutableList from NuGet package Microsoft.Bcl.Immutable version 1.0.34 and also 1.1.22-beta When removing items from the immutable list the performance is very slow. For an ImmutableList containing 20000 integer values (1...20000) if starting to remove from value 20000 to 1 it takes about 52 seconds to remove all items from the list. If I do the same with a generic List<T> where I create a copy of the list after each remove operation it

Returning a new ImmutableList that is an existing list plus an extra element

我的梦境 提交于 2019-12-14 03:57:31
问题 I'm using Google's ImmutableList class http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableList.html I'm looking for a method which takes an existing ImmutableList and an extra element (of the same type), and returns a new ImmutableList that contains the old elements plus the new one. Perhaps I'm missing something obvious in the docs? 回答1: public static final ImmutableList<Foo> result = new ImmutableList.Builder<Foo>() .addAll(originalList) .add(new

Immutable List and Typescript proper way to define an array of objects with type

痞子三分冷 提交于 2019-12-11 05:11:19
问题 Here is my JSON data which i get from the server [ { "property1": 1, "property2": "asd", "property3": 2 }, { "property1": 1, "property2": "asd", "property3": 2 }, { "property1": 1, "property2": "asd", "property3": 2 } ] I want to define Immutable List object which uses this interface export interface myObject { propert1: number, propert2: string, propert3: number } I tried something like this but its not working : private myObjectList: Immutable.List<myObject> = Immutable.List([]); and then

Slow performance from ImmutableList<T> Remove method in Microsoft.Bcl.Immutable

夙愿已清 提交于 2019-12-04 08:05:49
Experiencing some unexpected performance from Microsoft ImmutableList from NuGet package Microsoft.Bcl.Immutable version 1.0.34 and also 1.1.22-beta When removing items from the immutable list the performance is very slow. For an ImmutableList containing 20000 integer values (1...20000) if starting to remove from value 20000 to 1 it takes about 52 seconds to remove all items from the list. If I do the same with a generic List<T> where I create a copy of the list after each remove operation it takes about 500 ms. I was a bit surprised by these results since I thought the ImmutableList would be

Regarding immutable List (created by Arrays.asList())

橙三吉。 提交于 2019-11-30 07:06:43
问题 When we create a list from an array using java.util.Arrays.asList() , the list is immutable. I am just curious to know why do we want to create a immutable list when the basic purpose of List (or Set or Map ) is to have dynamic size and to be able to add, remove elements at will. When we need a fixed size data structure we go for Array and when we need a dynamic data structure we go for List or Set or Map etc. So what is the purpose of having a immutable list? I came across this while working

Regarding immutable List (created by Arrays.asList())

蹲街弑〆低调 提交于 2019-11-29 01:26:57
When we create a list from an array using java.util.Arrays.asList() , the list is immutable. I am just curious to know why do we want to create a immutable list when the basic purpose of List (or Set or Map ) is to have dynamic size and to be able to add, remove elements at will. When we need a fixed size data structure we go for Array and when we need a dynamic data structure we go for List or Set or Map etc. So what is the purpose of having a immutable list? I came across this while working on my assignment. When we create a list from an array using java.util.Arrays.asList() , the list is