Slide 1

Slide 1 text

Workshop Converting Java to Kotlin Corneil du Plessis @corneil Bring your own code.

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Agenda • Brief overview of Kotlin • Converting Ping Pong TDD – Roman Numerals, more... • Bring your own code. • Questions and Discussions • Java Interoperability • Interesting language features

Slide 4

Slide 4 text

Kotlin Overview • Improve readability • Reduce cognitive load • Functional and Object Oriented • Immutability

Slide 5

Slide 5 text

Kotlin – Functional and Object-Oriented

Slide 6

Slide 6 text

Zoom

Slide 7

Slide 7 text

Zoom

Slide 8

Slide 8 text

Zoom

Slide 9

Slide 9 text

Zoom

Slide 10

Slide 10 text

Kotlin – Functional and Object-Oriented

Slide 11

Slide 11 text

Kotlin – Data Class

Slide 12

Slide 12 text

Kotlin - Functions

Slide 13

Slide 13 text

Kotlin – Scope functions Name Invocation It / this Lambda result or object let receiver.let {} it {} with with(receiver) {} this {} run receiver.run {} this {} apply receiver.apply {} this receiver also receiver.also {} it receiver

Slide 14

Slide 14 text

Converting code • Converting Ping Pong TDD • Strap in....

Slide 15

Slide 15 text

Converting – Add dependencies

Slide 16

Slide 16 text

Kotlin – Maven Dependencies

Slide 17

Slide 17 text

Kotlin – Maven Plugins • https://gist.github.com/corneil/fdbac43fbc2b0909ea0cb6a0d0fd146a

Slide 18

Slide 18 text

Kotlin – Maven Plugin

Slide 19

Slide 19 text

Kotlin – Maven Java Plugin configuration

Slide 20

Slide 20 text

Interesting Kotlin features – Java interoperability • @JvmName • @get:JvmName • @set:JvmName • @JvmStatic • @JvmField • @JvmOverloads • @JvmDefault • @Throws • @JvmSuppressWildcards • @JvmMultifileClass

Slide 21

Slide 21 text

Kotlin - @JvmOverloads

Slide 22

Slide 22 text

Kotlin - Destructuring Declarations

Slide 23

Slide 23 text

Kotlin – Delegated Properties • lazy • Non-Primitives. • notNull • Primitives • observable • Lambda is invoked when modified • vetoable • Lambda can prevent an update by returning false

Slide 24

Slide 24 text

Kotlin –Delegated Properties

Slide 25

Slide 25 text

Kotlin - Delegation

Slide 26

Slide 26 text

Resources • Kotlin https://kotlinlang.org/ • Kotlin Reference https://kotlinlang.org/docs/reference/ • Kotlin Playground https://play.kotlinlang.org/ • Tutorials https://kotlinlang.org/docs/tutorials/ • More https://kotlinlang.org/docs/resources.html • Awesome Kotlin https://kotlin.link/