Posts

Showing posts with the label Kotlin

Kotlin is Joy (caveat: Extension Functions)

  Rahul has an excellent summary —  https://goo.gl/8HZDSC  — of a host of time-saving features in #Kotlin (TL;DR “ Why aren’t you using Kotlin yet? Also, #JetBrains ? ”) including #Anko , Data Classes, and Extension Functions.  The last one caught my eye, it’s a ludicrously useful feature, and also one that can (will!) trip up a lot of people. Extension Functions in Kotlin are simply plain old static functions that implicitly take an instance of the receiver class as a parameter when the function is defined, and then operate on it. You, therefore, have access to all members of the class inside your function block.  There is no connection to the receiver class in any other form The target classes are not modified. Extensions are visible from Java reflection as static methods in the classes they are defined in (.i.e. in package-classes for top-level extension functions). (°)  The issue?  If you define an extension function with the same sig...