Extension functions

Extension functions are a beautiful feature of Kotlin. Extension functions allow us to add the functions in the native class sets. All extension functions are statically resolved. Check out DateExtension.kt, it has three extension functions written for Long objects. They return different date formats. The code inside it may look a bit strange, which we will discuss in the following section: 

    fun Long.getShortDate(): String {      val getFormattedDate: dynamic = js("window.getShortDate")      return getFormattedDate(this)    }    fun Long.getFullDate(): String {      val getFormattedDate: dynamic = js("window.getFullDate")      return getFormattedDate(this)    }    fun Long.getFullWeekDay(): String {      val getFormattedDate: dynamic = js("window.getFullWeekDay" ...

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.