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

Kids, Play Nice! Kotlin-Java Interop In Mind

Kids, Play Nice! Kotlin-Java Interop In Mind

Although it may be many developers’ favourite by now, Kotlin is not *yet* everywhere.
In the desire to deliver a library or an API that will provide the best experience for both Kotlin and Java developers, there are a few things to be aware of.

Whether you’re creating a library or exposing an API for either external or internal use, you should make sure Kotlin and Java play nice.

This talk will present some of our experiences at Nexmo in the Kotlin-Java interop realm. It will share some challenges and considerations we faced, some gotchas we encountered and some tips that will make your lives easier when striving for great developer experience.

Britt Barak

August 26, 2019
Tweet

More Decks by Britt Barak

Other Decks in Programming

Transcript

  1. 1HWOYY3GWG OJ A G ?OIK Ech`]b ( DUjU CbhYfcd Cb

    ]bX 3WOYY 3GWG 8UUM K 5K K U KW 6 KWY
  2. 1HWOYY3GWG = AJ PP S I IM J LA S

    A MyFileKt.java MyFile.kt InnerClass.java
  3. 1HWOYY3GWG = AJ PP S I IM J LA S

    A MyFile.kt InnerClass.class MyFileKt.class
  4. UY OT G G ib gYbX@jYbh#YjYbh5 @jYbh:$ jU` YjYbh 8

    @jYbh#q$ cbjYfgUh]cb:)gYbX@jYbh#YjYbh$
  5. UY OT G G ib gYbX@jYbh#YjYbh5 @jYbh:$ jU` YjYbh 8

    @jYbh#q$ cbjYfgUh]cb:)gYbX@jYbh#YjYbh$ jc]X gYbX@jYbh#@jYbh YjYbh $
  6. UY OT G G ib gYbX@jYbh#YjYbh5 @jYbh u $ jU`

    YjYbh 8 @jYbh#q$ cbjYfgUh]cb:)gYbX@jYbh#YjYbh$ jc]X gYbX@jYbh#@jYbh YjYbh $
  7. UY OT G G ib gYbX@jYbh#YjYbh5 @jYbh u $ jU`

    YjYbh 8 bi`` cbjYfgUh]cb:)gYbX@jYbh#YjYbh$ jc]X gYbX@jYbh#@jYbh YjYbh $
  8. UY OT G G ib gYbX@jYbh#YjYbh5 @jYbh:$ ib gYbX@jYbh#YjYbh5 @jYbh$

    jc]X gYbX@jYbh #;Hi``U `Y @jYbh YjYbh $ jc]X gYbX@jYbh #;HcbHi`` @jYbh YjYbh $
  9. UY OT G G ib [Yh@jYbhg#$ 5 # ihU `Y$F]gh7@jYbh

    u 9 u F]gh7@jYbh9 [Yh@jYbhg# $
  10. UY OT G G ib [Yh@jYbhg#$ 5 # ihU `Y$F]gh7@jYbh

    u 9 jU` YjYbhg 8 [Yh@jYbhg#$ jU` YjYbh 8 YjYbhg +R ;HcbHi`` F]gh7@jYbh9 [Yh@jYbhg# $
  11. UY OT G G ib [Yh@jYbhg#$ 5 # ihU `Y$F]gh7@jYbh9

    jU` YjYbhg 8 [Yh@jYbhg#$ jU` YjYbh 8 YjYbhg +R ;HcbHi`` F]gh7;HcbHi`` @jYbh9 [Yh@jYbhg# $
  12. UY OT G G jU` hmdY 8 YjYbh)hmdY YjYbh)hmdY 8

    rhYlhs jU` gYbh 8 YjYbh)gYbh YjYbh)gYbh 8 hfiY Lhf]b[ [YhMmdY#$ Lhf]b[ gYhMmdY#$ cc`YUb ]gLYbh#$ jc]X gYhLYbh#$
  13. UY OT G G jU` hmdY 8 YjYbh)hmdY YjYbh)hmdY 8

    rhYlhs jU` gYbh 8 YjYbh)gYbh YjYbh)gYbh 8 hfiY YjYbh)kUgLYYb#$ Lhf]b[ [YhMmdY#$ Lhf]b[ gYhMmdY#$ cc`YUb ]gLYbh#$ jc]X gYhLYbh#$ cc`YUb kUgLYYb#$
  14. UY OT G G `Ugg JUmaYbh@jYbh 5 >ighca@jYbho jUf dfcdYfh]Yg

    5 Ud7Lhf]b[ <bm9 jUf U[YbhHUaY H dfcdYfh]Yg p
  15. UY OT G G `Ugg JUmaYbh@jYbh 5 >ighca@jYbho jUf dfcdYfh]Yg

    5 Ud7Lhf]b[ <bm9 jUf U[YbhHUaY m dfcdYfh]Yg p U[Ybh 8 dUmaYbh@jYbh)U[YbhHUaY U[Ybh 8 dUmaYbh@jYbh)[Yh<[YbhHUaY#$6
  16. 1HWOYY3GWG ( :T G G G UOJ UY OT NGWJ

    K UWJ hhdg5**_ch`]b`Ub[)cf[*Xc g*fY YfYb Y*_YmkcfX(fY YfYb Y) ha` UfX(_YmkcfXg
  17. UY OT G G igYf) T ]b T # cbjYfgUh]cb$

    igYf)]b# cbjYfgUh]cb$6
  18. 1HWOYY3GWG ( :T G G G UOJ @ KWGYUW SKYNUJ

    TGSK hhdg5**_ch`]b`Ub[)cf[*Xc g*fY YfYb Y*_YmkcfX(fY YfYb Y) ha` cdYfUhcfg(UbX(gdY ]U`(gma c`g
  19. UY OT G G cbjYfgUh]cb) h]aYg#@jYbhMmdY)<bgkYfYX$ cbjYfgUh]cb @jYbhMmdY)<bgkYfYX `Ugg >cbjYfgUh]cb

    F]gh7?UhY9 h]aYg#@jYbhMmdY hmdY$ oqp cbjYfgUh]cb) h]aYg#@jYbhMmdY)<bgkYfYX$
  20. UY OT G G `Ugg >cbjYfgUh]cb o cdYfUhcf ib d`ig#igYf

    5 NgYf$ o Ud]) c]b#]X igYf$ * q * p p cbjYfgUh]cb igYf
  21. UY OT G G `Ugg >cbjYfgUh]cb o cdYfUhcf ib d`ig#igYf

    5 NgYf$ o Ud]) c]b#]X igYf$ * q * p p cbjYfgUh]cb igYf
  22. UY OT G G `Ugg >cbjYfgUh]cb o cdYfUhcf ib d`ig#igYf

    5 NgYf$ o Ud]) c]b#]X igYf$ * q * p p cbjYfgUh]cb igYf cbjYfgUh]cb)d`ig#igYf$
  23. UY OT G G `Ugg >cbjYfgUh]cb o . S C

    M L " cdYfUhcf ib d`ig#igYf 5 NgYf$ o Ud]) c]b#]X igYf$ * q * p p cbjYfgUh]cb igYf cbjYfgUh]cb) c]b#igYf$
  24. UY OT G G AJ CL EC SCL P AMLSM

    )(" VNC ,, 0RP M SCL /> ;
  25. UY OT G G ib [Yh@jYbhg # cbjcCX5 Lhf]b[ cibh5

    Cbh AJ CL EC SCL P AMLSM )(" VNC ,, 0RP M SCL /> ;
  26. UY OT G G ib [Yh@jYbhg # cbjcCX5 Lhf]b[ cibh5

    Cbh ]`hYf5 #@jYbh$ (9 =cc`YUb$ AJ CL EC SCL P AMLSM )(" VNC ,, 0RP M SCL /> ;
  27. UY OT G G ib [Yh@jYbhg # cbjcCX5 Lhf]b[ cibh5

    Cbh ]`hYf5 #@jYbh$ (9 =cc`YUb$ 5 F]gh7@jYbh9 o* q *p AJ CL EC SCL P AMLSM )(" VNC ,, 0RP M SCL /> ;
  28. UY OT G G ib [Yh@jYbhg # cbjcCX5 Lhf]b[ cibh5

    Cbh ]`hYf5 #@jYbh$ (9 =cc`YUb$ 5 F]gh7@jYbh9 o* q *p AJ CL EC SCL P AMLSM )(" VNC ,, 0RP M SCL /> ; `]Ybh) [Yh@jYbhg# cbjcCX -+ Y (9 #Y)[YhMmdY#$ )YeiU`g#>ighca@jYbh)J<P @HM$$$6
  29. UY OT G G ib [Yh@jYbhg # cbjcCX5 Lhf]b[ cibh5

    Cbh ]`hYf5 #@jYbh$ (9 =cc`YUb$ 5 F]gh7@jYbh9 o* q *p AJ CL EC SCL P AMLSM )(" VNC ,, 0RP M SCL /> ; `]Ybh) [Yh@jYbhg# cbjcCX -+ Y (9 #Y)[YhMmdY#$ )YeiU`g#>ighca@jYbh)J<P @HM$$$6
  30. UY OT G G ib [Yh@jYbhg # cbjcCX5 Lhf]b[ ]`hYf5

    #@jYbh$ (9 =cc`YUb$ cibh5 Cbh$ 5 F]gh7@jYbh9 o* q *p AJ CL EC SCL P AMLSM VNC ,, 0RP M SCL /> ; `]Ybh) [Yh@jYbhg# cbjcCX Y (9 #Y)[YhMmdY#$ )YeiU`g#>ighca@jYbh)J<P @HM$$ -+$6
  31. UY OT G G ib gYbXMYlh# U`` U _5 #Lhf]b[$

    (9 Nb]h$ 8 * q * cbjYfUgUh]cb)gYbXMYlh#$ o Fc[)X# MYlh rLYbh5 "]hu $ p
  32. UY OT G G ib gYbXMYlh# U`` U _5 #Lhf]b[$

    (9 Nb]h$ 8 * q * cbjYfUgUh]cb)gYbXMYlh#$ o Fc[)X# MYlh rLYbh5 "]hu $ p cbjYfUgUh]cb)gYbXMYlh # hYlh (9 o Fc[)X# MYlh rLYbh5 bUaY rus$6 $6
  33. UY OT G G ib gYbXMYlh# U`` U _5 #Lhf]b[$

    (9 Nb]h$ 8 * q * cbjYfUgUh]cb)gYbXMYlh#$ o Fc[)X# MYlh rLYbh5 "]hu $ p cbjYfUgUh]cb)gYbXMYlh # hYlh (9 o Fc[)X# MYlh rLYbh5 bUaY rus$6 fYhifb Nb]h)CHLM<H>@6 p $6
  34. GSHJG 2WM SKTY tEch`]b5 k Yb fYhifb]b[ Nb]h tIdh]cb ,(

    <jc]X tIdh]cb -( Ech`]b ]bhYf U Y 1HWOYY3GWG
  35. UY OT G G ib gYbXMYlh# U`` U _5MYlh>U`` U

    _$ CbhYf U Y MYlh>U`` U _o ib cbLYbh#ag[ 5 Lhf]b[$ 5 Nb]h p
  36. UY OT G G ib gYbXMYlh# U`` U _5MYlh>U`` U

    _$ CbhYf U Y MYlh>U`` U _o ib cbLYbh#ag[ 5 Lhf]b[$ 5 Nb]h p cbjYfUgUh]cb)gYbXMYlh # c Y h5 MYlh>U`` U _oqp$ cbjYfgUh]cb)gYbXMYlh#ag[ (9 q$
  37. GSHJG 2WM SKTY tEch`]b5 k Yb fYhifb]b[ Nb]h tIdh]cb ,5

    <jc]X tIdh]cb -5 Ech`]b ]bhYf U Y tIdh]cb .5 DUjU ]bhYf U Y 1HWOYY3GWG
  38. UY OT G G ]bhYf U Y MYlh>U`` U _o

    jc]X cbLYbh#ag[ 5 Lhf]b[$6 p
  39. UY OT G G ]bhYf U Y MYlh>U`` U _o

    jc]X cbLYbh#ag[ 5 Lhf]b[$6 p gYbXMYlh#MYlh>U`` U _ U`` U _$
  40. UY OT G G cbjYfUgUh]cb) gYbXMYlh o ag[ (9 q

    p ]bhYf U Y MYlh>U`` U _o jc]X cbLYbh#Lhf]b[ ag[$6 p gYbXMYlh#MYlh>U`` U _ U`` U _$ cbjYfgUh]cb) gYbXMYlh#ag[ (9 q$
  41. UY OT G G jc]X ghUfh>U`` # Lhf]b[ U``YY >U``F]ghYbYf

    `]ghYbYf$ oqp ]bhYf U Y >U``F]ghYbYfo jc]X cb<bgkYfYX#>U`` U``$ p
  42. UY OT G G ghUfh>U``#igYfCX$ o Fc[)X# >U`` "]h)]X UbgkYfYXus$

    p jc]X ghUfh>U`` # Lhf]b[ U``YY >U``F]ghYbYf `]ghYbYf$ oqp ]bhYf U Y >U``F]ghYbYfo jc]X cb<bgkYfYX#>U`` U``$ p
  43. UY OT G G jc]X ghUfh>U`` # Lhf]b[ U``YY >U``F]ghYbYf

    `]ghYbYf$ oqp ]bhYf U Y >U``F]ghYbYfo jc]X cb<bgkYfYX#>U`` U``$ jc]X cbKY Y hYX#>U`` U``$ p
  44. UY OT G G `]Ybh) ghUfh>U``#igYfCX c Y h 5

    >U``F]ghYbYf o cjYff]XY ib cb<bgkYfYX# U``5 >U``$ oqp cjYff]XY ib cbKY Y hYX# U``5 >U``$ oqp p jc]X ghUfh>U`` # Lhf]b[ U``YY >U``F]ghYbYf `]ghYbYf$ oqp ]bhYf U Y >U``F]ghYbYfo jc]X cb<bgkYfYX#>U`` U``$ jc]X cbKY Y hYX#>U`` U``$ p
  45. UY OT G G RL CU M0J CL A JJ

    A JJCC* : LE ML0 JJ/LPTC C * A JJ* 0 JJ" - L ML0 JJ C CA C * A JJ* 0 JJ" - L "
  46. UY OT G G RL CU M0J CL A JJ

    A JJCC* : LE ML0 JJ/LPTC C * A JJ* 0 JJ" - L ML0 JJ C CA C * A JJ* 0 JJ" - L " S J P CLC , M@ CA * 0 JJ P CLC
  47. UY OT G G RL CU M0J CL A JJ

    A JJCC* : LE ML0 JJ/LPTC C * A JJ* 0 JJ" - L ML0 JJ C CA C * A JJ* 0 JJ" - L " S J P CLC , M@ CA * 0 JJ P CLC MSC C RL ML/LPTC C A JJ* 0 JJ" MSC C RL ML C CA C A JJ* 0 JJ"
  48. UY OT G G RL CU M0J CL A JJ

    A JJCC* : LE ML0 JJ/LPTC C * A JJ* 0 JJ" - L ML0 JJ C CA C * A JJ* 0 JJ" - L " S J P CLC , M@ CA * 0 JJ P CLC MSC C RL ML/LPTC C A JJ* 0 JJ" ML0 JJ/LPTC C LSMIC A JJ" MSC C RL ML C CA C A JJ* 0 JJ" ML0 JJ C CA C LSMIC A JJ"
  49. UY OT G G RL CU M0J CL A JJ

    A JJCC* : LE ML0 JJ/LPTC C * A JJ* 0 JJ" - L ML0 JJ C CA C * A JJ* 0 JJ" - L " S J P CLC , M@ CA * 0 JJ P CLC MSC C RL ML/LPTC C A JJ* 0 JJ" ML0 JJ/LPTC C LSMIC A JJ" MSC C RL ML C CA C A JJ* 0 JJ" ML0 JJ C CA C LSMIC A JJ" A JJ A JJCC J P CLC "
  50. UY OT G G AJ CL A JJ A JJCC

    ML0 JJ/LPTC C , ML0 JJ C CA C , "
  51. UY OT G G AJ CL A JJ A JJCC

    ML0 JJ/LPTC C , ML0 JJ C CA C , " A JJ AJ CL A JJCC ML0 JJ/LPTC C , ML0 JJ C CA C , "
  52. UY OT G G AJ CL A JJ A JJCC

    ML0 JJ/LPTC C , ML0 JJ C CA C , " A JJ AJ CL A JJCC ML0 JJ/LPTC C , ML0 JJ C CA C , "
  53. UY OT G G >cbjYfgUh]cbLYhh]b[g)_h jU` cb ][g 8 *

    q * cbjc>cb ][g 8 >cbjYfgUh]cbLYhh]b[gEh )[Yh>cb ][g#$
  54. UY OT G G >cbjYfgUh]cbLYhh]b[g)_h ; ]`Y5DjaHUaY#r>cb ][gs$ jU` cb

    ][g 8 * q * cbjc>cb ][g 8 >cb ][g) [Yh>cb ][g#$
  55. UY OT G G >cbjYfgUh]cbLYhh]b[g)_h ; ]`Y5Dja i`h] ]`Y>`Ugg ;

    ]`Y5DjaHUaY#r>cb ][gs$ jU` cb ][g 8 * q * cbjc>cb ][g 8 >cb ][g) [Yh>cb ][g#$
  56. UY OT G G `Ugg MYlh@jYbh o cadUb]cb c Y

    h o jU` MPJ@SM@OM 8 rhmdY 5 hYlhs ib i]`XYf 8 =i]`XYf#$ p p
  57. UY OT G G `Ugg MYlh@jYbh o cadUb]cb c Y

    h o jU` MPJ@SM@OM 8 rhmdY 5 hYlhs ib i]`XYf 8 =i]`XYf#$ p p MYlh@jYbh)>cadUb]cb) MPJ@SM@OM MYlh@jYbh)>cadUb]cb) i]`XYf#$
  58. UY OT G G `Ugg MYlh@jYbh o cadUb]cb c Y

    h o ;DjaA]Y`X jU` MPJ@SM@OM 8 rhmdY 5 hYlhs ;DjaLhUh] ib i]`XYf 8 =i]`XYf#$ p p MYlh@jYbh)MPJ@SM@OM MYlh@jYbh) i]`XYf#$
  59. UY OT G G ib bYk>cbjYfgUh]cb# bUaY5 Lhf]b[ c]b 5

    =cc`YUb 8 hfiY$ `]Ybh) bYk>cbjYfgUh]cb#TTam> UhTT hfiY$
  60. UY OT G G ;DjaIjYf`cUXg ib bYk>cbjYfgUh]cb# bUaY5 Lhf]b[ c]b

    5 =cc`YUb 8 hfiY$ `]Ybh) bYk>cbjYfgUh]cb#TTam> UhTT hfiY$ `]Ybh) bYk>cbjYfgUh]cb#TTam> UhTT$
  61. UY OT G G `Ugg @jYbh #hmdY 5 @jYbhMmdY 8

    @jYbhMmdY)>NLMI $ YjYbh 8 bYk @jYbh#@jYbhMmdY )>NLMI $
  62. UY OT G G `Ugg @jYbh ;DjaIjYf`cUXg cbghfi hcf #hmdY

    5 @jYbhMmdY 8 @jYbhMmdY)>NLMI $ YjYbh 8 bYk @jYbh#@jYbhMmdY )>NLMI $
  63. UY OT G G `Ugg @jYbh ;DjaIjYf`cUXg cbghfi hcf #hmdY

    5 @jYbhMmdY 8 @jYbhMmdY)>NLMI $ YjYbh 8 bYk @jYbh#@jYbhMmdY )>NLMI $ YjYbh 8 bYk @jYbh#$ YjYbh 8 bYk @jYbh#@jYbhMmdY )M@OM$
  64. UY OT G G ib gYbX<hhU YaYbh#dUh 5Lhf]b[$ V AJ

    CL PCL / AFC CL N F" A AF 2 JC M 2MRL UACN ML C" Y
  65. UY OT G G ;M fckg#A]`YHchAcibX@l Ydh]cb55 `Ugg$ ib gYbX<hhU

    YaYbh#dUh 5Lhf]b[$ V AJ CL PCL / AFC CL N F" A AF 2 JC M 2MRL UACN ML C" Y
  66. UY OT G G gYU`YX `Ugg m>U``LhUhig `Ugg <bgkYfYX 5

    m>U``LhUhig#$ `Ugg KY Y hYX#jU` fYUgcb5 Lhf]b[$ 5 m>U``LhUhig#$ c Y h Cb]h]U`]nYX 5 m>U``LhUhig#$
  67. UY OT G G k Yb#ghUhig$ o ]g <bgkYfYX (9

    * q * ]g KY Y hYX (9 * q * ]g Cb]h]U`]nYX (9 * q * q p
  68. UY OT G G k Yb#ghUhig$ o ]g <bgkYfYX (9

    * q * ]g KY Y hYX (9 * q * ]g Cb]h]U`]nYX (9 * q * q p ] #ghUhig ]bghUb Yc Cb]h]U`]nYX$ o* q *p Y`gY ] #ghUhig ]bghUb Yc KY Y hYX$ o* q *p q
  69. B S D ,) Hi`` gU Yhm -) JfcdYfhm dfY

    ]lYg .) Yh cX bUaYg /) FUa XU Uf[iaYbhg 0) A]`Y bUaYg 1) >cadUb]cb c Y hg 2) IjYf`cUXg 3) ?c iaYbh Yl Ydh]cbg 4) LYU`YX `UggYg ,+) IdYb `UggYg
  70. OTY 4NKI tLiddcfhYX > Y _g ]b DUjU `UggYg tNb_bckb

    Hi``bYgg tJfcdYfhm < Ygg tHc BUfX Ech`]b _YmkcfXg tFUa XU JUfUaYhYfg FUgh
  71. OTY 4NKI tA]`Y 9 JfY YfYb Yg 9 @X]hcf 9

    CbgdY h]cbg tM Y Y _g k]`` fib k Yb mci fib mcif cXY ]bgdY h]cbg #<bU`mnY 9 CbgdY h >cXYq$
  72. ( 8KY U W NGTJ JOWY t?Yg][b k]h mcif UbXg

    tMYgh k]h Ub Udd 1HWOYY3GWG