February 2020
Intermediate to advanced
412 pages
9h 36m
English
When you are doing RxJava work in Kotlin, the creation of extension functions is immensely helpful. We will now show a non-reactive example and cover the reactive case later.
Say we want to add a convenient function to LocalDate in order to quickly compute the number of days to another LocalDate. Rather than invoking verbose helper classes to do this task repeatedly, we can quickly add an extension function to LocalDate called numberOfDaysTo(), as shown here (the ch12_03.kt example):
import java.time.LocalDate import java.time.temporal.ChronoUnit fun main(args: Array<String>) { val startDate = LocalDate.of(2017,5,1) val endDate = LocalDate.of(2017,5,11) val daysBetween = startDate.numberOfDaysTo(endDate) println(daysBetween) ...Read now
Unlock full access