Slide 1

Slide 1 text

designing & developing for mobile Demoday, 05/03/2018 Harri Kirik, engineer Kotlin: Collections

Slide 2

Slide 2 text

Kotlin KOTLIN: COLLECTIONS #kotlin

Slide 3

Slide 3 text

Mutable and immutable KOTLIN: COLLECTIONS #collections

Slide 4

Slide 4 text

Autogenerated: 1. equals()/hashCode() pair 2. toString() 3. componentN() functions 4. copy() function KOTLIN: COLLECTIONS #collections

Slide 5

Slide 5 text

KOTLIN: COLLECTIONS val numbers: MutableList = mutableListOf(1, 2, 3) val readOnlyView: List = numbers println(numbers) // prints "[1, 2, 3]" numbers.add(4) println(readOnlyView) // prints "[1, 2, 3, 4]" readOnlyView.clear() // -> does not compile val strings = hashSetOf("a", "b", "c", "c") assert(strings.size == 3) #demoday

Slide 6

Slide 6 text

No dedicated syntax KOTLIN: COLLECTIONS #collections

Slide 7

Slide 7 text

listOf(), mutableListOf(), setOf(), mutableSetOf() KOTLIN: COLLECTIONS #collections

Slide 8

Slide 8 text

KOTLIN: COLLECTIONS val mutable = mutableListOf(1, 2, 3) val snapshot = mutable.toList() mutable.add(4) println(mutable) // prints "[1, 2, 3, 4]" println(snapshot) // prints "[1, 2, 3]" #demoday

Slide 9

Slide 9 text

KOTLIN: COLLECTIONS val mutable = mutableListOf(1, 2, 3) val snapshot = mutable.toList() snapshot.add(4) // Will not compile! val snapshot2 = snapshot.plus(4) // Returns a new list println(snapshot2 ) // prints "[1, 2, 3, 4]" #demoday

Slide 10

Slide 10 text

http:// lab.mobi designing & developing for mobile thanks Questions?