October 2018
Intermediate to advanced
370 pages
9h 15m
English
Let's see how to get an immutable list from the Kotlin function to Java. Create an immutable list in the getImmutableList function and return the list:
fun getImmutableList() : List<Int> { val list = listOf(1,2,3,4,5) return list}
Get a Kotlin list by calling the getImmutableList function and displaying list elements. See the following example:
public static void main(String args[]) { System.out.println("Kotlin immutable list"); List<Integer> listFromKotlin = CallKotlinKt.getImmutableList(); for (int i = 0; i < listFromKotlin.size(); i++) { System.out.println("Element " + listFromKotlin.get(i)); }}
Since we know that the immutable list cannot be updated, we can read the list but cannot add or update elements. ...
Read now
Unlock full access