July 2018
Intermediate to advanced
242 pages
8h 6m
English
Let's test our implementation. For the sake of the test, we can assume that the getPlayers() function returns the following results:
fun getPlayers(): List<Player>? = listOf( Player("Stefan Madej", 109), Player("Adam Ondra", 323), Player("Chris Charma", 239))
The code we have implemented is going to print the following output to the console:
3 players records fetched[Player(name=Stefan Madej, bestScore=109), Player(name=Adam Ondra, bestScore=323), Player(name=Chris Charma, bestScore=239)]Best Player: Adam Ondra
Note that, in the case of the apply() function, we can omit this keyword while accessing class properties and functions inside the function lambda block:
apply { print("Best Player: $name")}
It was just used in the ...
Read now
Unlock full access