How to create an immutable list in Kotlin that is also an immutable list in Java?
问题 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