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

End-to-end Kotlin in a Java Enterprise [CON1714...

End-to-end Kotlin in a Java Enterprise [CON1714, JavaOne 2017]

Venue: Moscone West - Room 2012; San Francisco, CA.
Time: 11:00AM - 11:45AM, 2nd October 2017
Speakers: @oluwasayo_ and @kingsleyadio
Tags: Kotlin, Java, JavaEE, Android, Spring, Maven, Gradle, Vaadin, KAPT, IntelliJ, Eclipse, NetBeans, AS

Sayo Oladeji

October 02, 2017
Tweet

More Decks by Sayo Oladeji

Other Decks in Programming

Transcript

  1. Sayo Oladeji • Developer at Vaadin, Finland • Works on

    the Pro Tools team, responsible for commercial products like Vaadin Charts, TestBench, etc • Lover of the English Premier League • Twitter: @oluwasayo_
  2. Kingsley Adio • Software Developer at HelloFresh, Germany • Eats

    Nougat for a living (Android) • Kotlin enthusiast • Twitter: @kingsleyadio
  3. Our background • Java SE 6, EE 6 • Ant-based

    NetBeans project • No CI/CD, No cloud • SOA with ESB via SOAP
  4. Artifact Size Kilobytes 0 1500 3000 4500 6000 Groovy (v2.4.12)

    Clojure (v1.8.0) Scala (v2.12.3) Kotlin (v1.1.50)
  5. Method Count Methods 0 15000 30000 45000 60000 Groovy (v2.4.12)

    Clojure (v1.8.0) Scala (v2.12.3) Kotlin (v1.1.50) 6,315 50,794 16,023 28,866
  6. Cmd + Opt + Shift + K • GCM client’s

    Message.java (299 lines) • After conversion in IDEA (259 lines) • After hand-tuning (25 lines) https://goo.gl/u4dvNC
  7. How we Kotlin • It’s okay to write Java-like Kotlin

    in the beginning. • It’s awesome to write idiomatic Kotlin as you evolve.
  8. Java Varargs public Stuff doStuff(int start, int... steps) {
 //

    Do some stuff.
 } public Stuff doStuff(int start, int[] steps) {
 // Do some stuff.
 }
  9. JAX-RS default @GET
 @JvmOverloads
 fun getPhone(@QueryParam(“name”) name: String = “iPhone”)


    = em.find<Phone>(name) @GET
 fun getPhone(@QueryParam(“name”) 
 @DefaultValue(“iPhone”) name: String)
 = em.find<Phone>(name)
  10. CDI/EJB singletons @Singleton
 object MyBean {
 // Bean members.
 }

    @Singleton
 class MyBean {
 // Bean members.
 }
  11. JPA entities @Entity
 data class MyEntity {
 // Entity members.


    } @Entity
 class MyEntity {
 // Entity members.
 }
  12. Reserved words private inline fun <reified T : AbstractElement> select()

    = `$`(T::class.java) select<ButtonElement>().caption("Submit").first().click()
  13. Lazy delegate private val myTextView: TextView by lazy { findViewById(R.id.my_text_view)

    } LazyThreadSafety.SYNCHRONIZED LazyThreadSafety.PUBLICATION LazyThreadSafety.NONE
  14. Notes We can help report bugs. Quick hotfix updates come

    between patch releases https://kotl.in/issue