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

Travelling across Asia - Our journey from Java ...

Travelling across Asia - Our journey from Java to Kotlin

Kotlin has established itself in the Android development community since v1.0 last year, and with official support announced at I/O this year, it’s an exciting time to get started with this language in your work.

This talk will take you through Deliveroo’s journey from a full Java codebase to using Kotlin across the project. Learn how to get your colleagues involved and convert them to Kotlin supporters. You will also learn how they got started, the problems they ran into and how Kotlin can improve your codebase, your app and your sanity.

Maria Neumayer

October 27, 2017
Tweet

More Decks by Maria Neumayer

Other Decks in Programming

Transcript

  1. TRAVELLING ACROSS ASIA OUR JOURNEY FROM JAVA TO KOTLIN Amal

    Kakaiya @K4KYA Maria Neumayer @marianeum
  2. Java Kotlin AutoValue/Lombok Data classes Streams support Standard lib functions

    Retrolambda Built in lambda support Butterknife Kotterknife/delegate properties
  3. private final mapToId(Ljava/util/List;)Ljava/ util/List; L0 LINENUMBER 2 L0 ALOAD 1

    CHECKCAST java/lang/Iterable ASTORE 2 ———————— 75 more lines ————————
  4. private final List mapToId(List items) { Iterable $receiver$iv = (Iterable)items;

    Collection destination$iv$iv = (Collection)(new ArrayList(CollectionsKt.collectionSizeOrDefault($receiver $iv, 10))); Iterator var5 = $receiver$iv.iterator(); while(var5.hasNext()) { Object item$iv$iv = var5.next(); Item it = (Item)item$iv$iv; String var12 = it.id; destination$iv$iv.add(var12); } return (List)destination$iv$iv; }
  5. VERIFY WITH CAPTORS TOTALLY SHOULD HAVE BEEN ARGUMENTKAPTOR… JUS’ SAYIN’

    @Captor lateinit var captor: KArgumentCaptor<ScreenUpdate> verify(screen).updateScreen(captor.capture()) val update = captor.lastValue
  6. MOCKS AND NULLABLE /** Matches any object, excluding nulls. */

    inline fun <reified T : Any> any() = Mockito.any(T::class.java) ?: createInstance<T>() /** Matches anything, including nulls. */ inline fun <reified T : Any> anyOrNull(): T = Mockito.any<T>() ?: createInstance<T>()
  7. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent -> login(password()) }
  8. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent -> login(password()) }
  9. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent -> login(password()) }
  10. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE ! ! !

    ! ! ! ! ! private val passwordActionListener = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent -> login(password()) }
  11. CONSIDER NULLABILITY WHEN IMPLEMENTING A JAVA INTERFACE private val passwordActionListener

    = TextView.OnEditorActionListener { _: TextView, _: Int, _: KeyEvent? -> login(password()) } "
  12. IMMUTABILITY? private Item addNameToItem(Item item, Name other) { ItemBuilder builder

    = item.toBuilder() builder.name(other.getName()); return builder.build() }
  13. IMMUTABILITY? private Item addNameToItem(Item item, Name other) { ItemBuilder builder

    = item.toBuilder() builder.name(other.getName()); return builder.build() } private fun addNameToItem(item: Item, other: Name): Item { return item.copy(name = other.name) }
  14. LINKS ▸ Christina Lee & Jake Wharton - Kotlin is

    here, Life is great and everything will be OK: https://youtu.be/fPzxfeDJDzY ▸ Mockito Kotlin: https://github.com/nhaarman/mockito-kotlin ▸ Kotlin Koans: https://kotlinlang.org/docs/tutorials/koans.html