Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting Kotlin in Your Codebase

Getting Kotlin in Your Codebase

http://oredev.org/2016/sessions/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
Tweet

More Decks by Eric Cochran

Other Decks in Programming

Transcript

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

    { logClick() } view.setOnClickListener (listener)
  2. 5 Nullability Nullability in the type system var name: String?

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

    deck and such. Lateinit Available for non-null, var, non-primitive properties
  4. 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 } }
  5. 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(…) } }
  6. 9 data class Train(val number: Int, val name: String =

    “”, val stations: List<Station>) Generated equals, hashCode, copy Allow implementing interfaces Data Classes
  7. 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