July 2018
Intermediate to advanced
242 pages
8h 6m
English
As a result, we are able to call the swap function on any instance of the Array class. Let's consider the following example:
val array: Array<String> = arrayOf("a", "b", "c", "d")array.swap("c", "b")print(array.joinToString())
This results in printing the following output to the console:
a, c, b, d
As you can see, we can access the current instance of the class inside the extension function using the this keyword.
Read now
Unlock full access