Slide 1

Slide 1 text

Kotlin 1.3 ͞ΒͬͱContracts + α LINE Developers Meetup #47 in Fukuoka @dashimaki_dofu

Slide 2

Slide 2 text

ϓϩϑΟʔϧ • ໊લ: ߴ Յହ (Yoshiyasu KO) • ॴଐ: ϕΨίʔϙϨʔγϣϯ • AndroidΤϯδχΞ • : @dashimaki_dofu

Slide 3

Slide 3 text

ϓϩϑΟʔϧ ʮ͠ΜͪΌΜͷਓʯͱ֮͑ͯؼ͍ͬͯͩ͘͞ • ໊લ: ߴ Յହ (Yoshiyasu KO) • ॴଐ: ϕΨίʔϙϨʔγϣϯ • AndroidΤϯδχΞ • : @dashimaki_dofu

Slide 4

Slide 4 text

What is Kotlin?

Slide 5

Slide 5 text

Kotlinʢ͜ͱΓΜʣ • 2013೥ JetBrains͕ࣾ։ൃͨ͠ ΦϒδΣΫτࢦ޲ܕݴޠ • JVM্Ͱಈ࡞ • Android Studio 3.0ΑΓ ެࣜαϙʔτ

Slide 6

Slide 6 text

2018.10.30 Kotlin 1.3ϦϦʔεʂ

Slide 7

Slide 7 text

Kotlin 1.3 • Coroutines ਖ਼ࣜ൛ • Kotlin/Native β൛ • Contracts • when Ҿ਺ͷείʔϓ࠷దԽ etc...

Slide 8

Slide 8 text

Kotlin 1.3 • Coroutines ਖ਼ࣜ൛ • Kotlin/Native β൛ • Contracts • when Ҿ਺ͷείʔϓ࠷దԽ etc... ࠓ೔࿩͢ͷ͸ͪ͜Β

Slide 9

Slide 9 text

Contracts

Slide 10

Slide 10 text

Contracts = ܖ໿ • ؔ਺ͷৼΔ෣͍Λʮܖ໿ʯ͢Δ • ίϯύΠϥʹؔ਺ͷৼΔ෣͍Λڭ͑Δ

Slide 11

Slide 11 text

?????

Slide 12

Slide 12 text

Smart Cast fun foo(s: String?) { if (s != null) s.length }

Slide 13

Slide 13 text

Smart Cast fun foo(s: String?) { if (s != null) s.length } T͸/VMMBCMF

Slide 14

Slide 14 text

Smart Cast fun foo(s: String?) { if (s != null) s.length } /PU/VMMΛอূ

Slide 15

Slide 15 text

Smart Cast fun foo(s: String?) { if (s != null) s.length } /PU/VMMΛอূ ͕ෆཁ

Slide 16

Slide 16 text

ྫ: isNullOrEmpty() fun foo(s: String?) { if (!s.isNullOrEmpty()) s!!.length } ~ Kotlin 1.2

Slide 17

Slide 17 text

ྫ: isNullOrEmpty() fun foo(s: String?) { if (!s.isNullOrEmpty()) s!!.length } T͕ʮOVMMPSۭจࣈʯͰ͋Ε͹USVF OVMMͰ΋ۭจࣈͰ΋ͳ͚Ε͹GBMTF GBMTFͰ͋Ε͹/PU/VMM͕อূ͞ΕΔ͸ͣ ~ Kotlin 1.2

Slide 18

Slide 18 text

ྫ: isNullOrEmpty() fun foo(s: String?) { if (!s.isNullOrEmpty()) s!!.length } ίϯύΠϥ͸JT/VMM0S&NQUZͷʮৼΔ෣͍ʯ͕෼͔Βͳ͍ 4NBSU$BTU͕ޮ͔ͳ͍ɾɾɾ ~ Kotlin 1.2

Slide 19

Slide 19 text

ྫ: isNullOrEmpty() fun foo(s: String?) { if (!s.isNullOrEmpty()) s.length } Kotlin 1.3 JT/VMM0S&NQUZʹ࣮૷͞Εͨ$POUSBDUTʹΑͬͯ 4NBSU$BTU͕ޮ͘Α͏ʹͳΔʂ

Slide 20

Slide 20 text

ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } Kotlin 1.3

Slide 21

Slide 21 text

ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } Kotlin 1.3

Slide 22

Slide 22 text

ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } %4- ޙड़ Ͱهड़͞ΕΔ Kotlin 1.3

Slide 23

Slide 23 text

ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } GBMTFΛฦ࣌͢ Kotlin 1.3

Slide 24

Slide 24 text

ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } GBMTFΛฦ࣌͢ /PU/VMMΛอূ͢Δ͜ͱΛ ܖ໿͢Δ Kotlin 1.3

Slide 25

Slide 25 text

ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } GBMTFΛฦ࣌͢ /PU/VMMΛอূ͢Δ͜ͱΛ ܖ໿͢Δ ίϯύΠϥʹؔ਺ͷৼΔ෣͍Λ఻͑Δ͜ͱ͕Ͱ͖Δ Kotlin 1.3

Slide 26

Slide 26 text

Contracts DSL • returns() • ؔ਺ͷ࣮ߦʹ੒ޭͨ࣌͠ • returns(Boolean?) • ؔ਺͕Ҿ਺ͷ஋Λฦͨ࣌͠ • returnsNotNull() • ؔ਺͕NotNullΛฦͨ࣌͠ • callsInPrace(block, InvocationKind) • block ͕ݺ͹ΕΔճ਺Λ InvocationKind Ͱอূ͢Δ

Slide 27

Slide 27 text

Contracts DSL • returns() • ؔ਺ͷ࣮ߦʹ੒ޭͨ࣌͠ • returns(Boolean?) • ؔ਺͕Ҿ਺ͷ஋Λฦͨ࣌͠ • returnsNotNull() • ؔ਺͕NotNullΛฦͨ࣌͠ • callsInPrace(block, InvocationKind) • block ͕ݺ͹ΕΔճ਺Λ InvocationKind Ͱอূ͢Δ ࣗ෼Ͱ$POUSBDUΛ࡞ΕΔ $VTUPN$POUSBDUT

Slide 28

Slide 28 text

when Ҿ਺ͷείʔϓ࠷దԽ

Slide 29

Slide 29 text

when Ҿ਺ͷείʔϓ࠷దԽ fun Request.getBody() { val response = executeRequest() return when (response) { is Success -> response.body is HttpError -> throw HttpException(response.status) } } ~ Kotlin 1.2

Slide 30

Slide 30 text

when Ҿ਺ͷείʔϓ࠷దԽ fun Request.getBody() { val response = executeRequest() return when (response) { is Success -> response.body is HttpError -> throw HttpException(response.status) } } ~ Kotlin 1.2 ϩʔΧϧม਺Λ͜͜Ͱ ఆٛ͢Δඞཁ͕͋Δ

Slide 31

Slide 31 text

when Ҿ਺ͷείʔϓ࠷దԽ fun Request.getBody() { val response = executeRequest() return when (response) { is Success -> response.body is HttpError -> throw HttpException(response.status) } } ~ Kotlin 1.2 ϩʔΧϧม਺Λ͜͜Ͱ ఆٛ͢Δඞཁ͕͋Δ XIFO͚ͩͰ࢖͏ม਺ͷείʔϓ͕޿͕ͬͯ͠·͏

Slide 32

Slide 32 text

when Ҿ਺ͷείʔϓ࠷దԽ fun Request.getBody() = when (val response = executeRequest()) { is Success -> response.body is HttpError -> throw HttpException(response.status) } Kotlin 1.3

Slide 33

Slide 33 text

when Ҿ਺ͷείʔϓ࠷దԽ fun Request.getBody() = when (val response = executeRequest()) { is Success -> response.body is HttpError -> throw HttpException(response.status) } Kotlin 1.3 Ҿ਺಺ͰϩʔΧϧม਺͕ ఆٛͰ͖Δ

Slide 34

Slide 34 text

when Ҿ਺ͷείʔϓ࠷దԽ fun Request.getBody() = when (val response = executeRequest()) { is Success -> response.body is HttpError -> throw HttpException(response.status) } Kotlin 1.3 Ҿ਺಺ͰϩʔΧϧม਺͕ ఆٛͰ͖Δ Ҿ਺Ͱར༻͢Δม਺ͷείʔϓΛ XIFOϒϩοΫ಺ͰऩΊΔ͜ͱ͕Ͱ͖Δ \

Slide 35

Slide 35 text

ࠓ೔࿩ͨ͜͠ͱ • Contract • ίϯύΠϥʹؔ਺ͷʮৼΔ෣͍ʯΛ఻͑Δ • ελϯμʔυϥΠϒϥϦʹ΋૊Έࠐ·Ε͍ͯΔ • DSL Ͱهड़͞ΕΔ • Custom Contracts ΋ఆٛͰ͖Δ • when จͷҾ਺ͷείʔϓ࠷దԽ • ϩʔΧϧม਺ΛҾ਺಺ͰఆٛͰ͖Δ • when ϒϩοΫ಺ʹείʔϓ͕ऩΊΒΕΔ

Slide 36

Slide 36 text

·ͱΊ

Slide 37

Slide 37 text

͔Ώ͍ॴʹ ख͕ಧ͍ͨκʂ

Slide 38

Slide 38 text

͡Ό ͦΏ͜ͱͰʙ