Getting Kotlin in Your Codebase

Getting Kotlin in Your Codebase

Excitement swirls around Kotlin, and we developers want it in our codebases. From an Android engineer's point of view, Eric will talk about the best ways to start using Kotlin at work and what parts of a Android codebase really benefit from Kotlin usage. With the 1.0 stable release, convincing your coworkers to get Kotlin into at least your tests is an endeavor worth undertaking!


Eric Cochran

November 10, 2016


  1. Getting Kotlin in Your Codebase Eric Cochran Oredev November 10,

  2. Kotlin Value Add Reduce Verbosity Nullability Lateinit Data Classes Mutability

    Extension Functions
  3. 3 Reduce Verbosity Lambdas val listener: (View) -> Unit =

    { logClick() } view.setOnClickListener (listener)
  4. 4 Reduce Verbosity Default Parameters fun print(list: List<String>, count: Int

    = list.size())
  5. 5 Nullability Nullability in the type system var name: String?

    = null Safe calls with ?. val name: String? = Assert not null with !! val name: String =!! Compiler Tracking if ( != null) return
  6. 6 Some explanatory text to introduce the theme of the

    deck and such. Lateinit Available for non-null, var, non-primitive properties
  7. 7 Some explanatory text to introduce the theme of the

    deck and such. Lateinit Easy Dependency Injection class MyView { private lateinit var dependency: Dependency fun setup(dependency: Dependency) { this.dependency = dependency } }
  8. 8 Some explanatory text to introduce the theme of the

    deck and such. Lateinit Tests public class MyViewTest { private lateinit var view: MyView @Setup fun setup() { view = MyView(…) view.setup(…) } }
  9. 9 data class Train(val number: Int, val name: String =

    “”, val stations: List<Station>) Generated equals, hashCode, copy Allow implementing interfaces Data Classes
  10. 10 Real immutable collections by default List vs MutableList Set

    vs MutableSet Map vs MutableMap Covariant mutable collections: val textViews: List<TextView> = listOf(name, badge) val views: List<View> = textViews Mutability and Immutability
  11. 11 Ending Util Hell @file:JvmName(“TextViewUtils”) fun TextView.isUserSet(user: User) = getText()

    == Extension Functions
  12. 12 Measuring Performance var tock = measureTimeMillis { fetchAndSetNames() }

  13. 13 Why Kotlin? Standard Library Scala: ~50K methods Groovy: ~30K

    methods Kotlin: ~6K methods
  14. 14 Convert to Kotlin Alt + Cmd + Shift +

  15. 15 @Eric_Cochran