available, both Java invocations now compile public class Main { GreetingFunctionsKt.helloFunctions("Yay", "functions"); GreetingFunctionsKt.helloFunctions("Yay"); } @n8ebel #androidsummit 28
accept a variable number of arguments T - use the vararg keyword - vararg param is then treated as an array of type T - default value must now be an array @n8ebel #androidsummit 38
the last one Can be used in any order if: - other params are called using named argument syntax - last param is a function passed outside the parentheses @n8ebel #androidsummit 40
4 "Spreading" can be used alone, or with other passed varargs as well 4 input array to the vararg parameter is handled in order @n8ebel #androidsummit 45
Is the logic going to be needed outside the current function? 4 Does the logic need to be tested in isolation? 4 Is the enclosing function still readable? @n8ebel #androidsummit 77
call the function without dot or parentheses val attendee = ConferenceAttendee() attendee.addInterest("Kotlin") attendee addInterest "Kotlin" @n8ebel #androidsummit 95
2) { println(i) // prints 0,2,4,6,8 } "key" to someValue // creates a Pair var result: Boolean result = true or false // perform logical operations result = true and false @n8ebel #androidsummit 97
cleanup/ simplify/extend common apis 4 Now seeing community supported examples of this 4 Android KTX: https://github.com/android/android- ktx 4 Anko: https://github.com/Kotlin/anko @n8ebel #androidsummit 126
totalDownloadSize = downloadRecords.sumBy { it.downloadSize } // sort all DownloadRecords based on download time val sortedDownloadEntities = downloadRecords.sortedByDescending { record -> record.downloadTime } @n8ebel #androidsummit 131
to their parent enrollmentKey val entitiesGroupedByEnrollmentKey = downloadRecords.groupBy { record -> record.enrollmentKey } // ensure we have a non-null collection and map all records to view models val viewModels = inputRecords.orEmpty().map { record -> createViewModel(record) } @n8ebel #androidsummit 132