A Friend In Need Is a Friend Indeed                          Kotlin / Java Interop                                    Andr...
Kotlin                          Modern Language for Industry                          •    Smart compiler              •  ...
Stuff               • Apache 2                  • IDE               • Target                     ➡   IntelliJ             ...
Outline                          4Wednesday, August 1, 12       4
Outline               •    Enhancing Existing APIs                   ➡      Extensions                   ➡      Splitting ...
Outline               •    Enhancing Existing APIs                   ➡      Extensions                   ➡      Splitting ...
Outline               •    Enhancing Existing APIs                   ➡      Extensions                   ➡      Splitting ...
Making Existing                           Things Nicer                                Extensions                          ...
Extensions               • Demo                          6Wednesday, August 1, 12       6
Collections & Variance  Java:  Kotlin:                          7Wednesday, August 1, 12              7
Declaration-Site Variance                          8Wednesday, August 1, 12                 8
Translation                              Ø                              java.util.List                          9Wednesday...
Translation: Inheritance                          10Wednesday, August 1, 12                10
Translation: Variance                          11Wednesday, August 1, 12             11
Calling Java From Kotlin                          12Wednesday, August 1, 12                12
Summary               • Use JDK collections in Kotlin               • Extend them with useful operations               • M...
Fighting NPEs                               Nullable Types                            Annotating Java CodeWednesday, Augus...
Nullable Types               • Demo                          15Wednesday, August 1, 12        15
Nullable Types Summary               •    null is a legitimate value, not a sin               •    No overhead (as opposed...
Annotations to The Rescue                                          String   String?       JSR 305: Annotations for Softwar...
Generics?!                               @NotNull                                doesnt                                 he...
More Use-Cases of @Kotlin                          19Wednesday, August 1, 12                 19
External Annotations                          20Wednesday, August 1, 12            20
It Is Not So Bad               • IDE aids annotating with quick fixes               • Some annotations can be inferred    ...
Statics                            Packages                          Class ObjectsWednesday, August 1, 12                 ...
Package-Level Code        file1.kt                               foo/namespace.class        file2.kt                        ...
Package-Level Code        file1.kt                                 foo/namespace.class                               Compil...
Package-Level Code        file1.kt                          foo/namespace.class                                           f...
Package-Level Code        file1.kt                                foo/namespace.class                                      ...
Kotlin Classes                          Have No StaticsWednesday, August 1, 12                     25
Class Object Translation                          26Wednesday, August 1, 12                26
Class Object Translation                               Only fields!                          26Wednesday, August 1, 12     ...
Resources            • Docs: http://kotlin.jetbrains.org            • Demo: http://kotlin-demo.jetbrains.com            • ...
Upcoming SlideShare
Loading in...5
×

[JVMLS 12] Kotlin / Java Interop

728

Published on

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
728
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

[JVMLS 12] Kotlin / Java Interop

  1. 1. A Friend In Need Is a Friend Indeed Kotlin / Java Interop Andrey BreslavWednesday, August 1, 12 1
  2. 2. Kotlin Modern Language for Industry • Smart compiler • Static typing ➡ Less boilerplate • Readability • Flexible abstractions • Tool support ➡ Powerful libraries • Interoperability 2Wednesday, August 1, 12 2
  3. 3. Stuff • Apache 2 • IDE • Target ➡ IntelliJ ➡ JVM (1.6) ➡ Web Demo ➡ JavaScript * • Build ➡ Ant ➡ Maven 3 * PlannedWednesday, August 1, 12 3
  4. 4. Outline 4Wednesday, August 1, 12 4
  5. 5. Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces 4Wednesday, August 1, 12 4
  6. 6. Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces • Fighting for Safety ➡ Nullable types ➡ Interaction with generics 4Wednesday, August 1, 12 4
  7. 7. Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces • Fighting for Safety ➡ Nullable types ➡ Interaction with generics • Statics ➡ Packages ➡ Class objects 4Wednesday, August 1, 12 4
  8. 8. Making Existing Things Nicer Extensions Variance TricksWednesday, August 1, 12 5
  9. 9. Extensions • Demo 6Wednesday, August 1, 12 6
  10. 10. Collections & Variance Java: Kotlin: 7Wednesday, August 1, 12 7
  11. 11. Declaration-Site Variance 8Wednesday, August 1, 12 8
  12. 12. Translation Ø java.util.List 9Wednesday, August 1, 12 9
  13. 13. Translation: Inheritance 10Wednesday, August 1, 12 10
  14. 14. Translation: Variance 11Wednesday, August 1, 12 11
  15. 15. Calling Java From Kotlin 12Wednesday, August 1, 12 12
  16. 16. Summary • Use JDK collections in Kotlin • Extend them with useful operations • Make them variant for Kotlin • At the expense of some unsoundness around the edges 13Wednesday, August 1, 12 13
  17. 17. Fighting NPEs Nullable Types Annotating Java CodeWednesday, August 1, 12 14
  18. 18. Nullable Types • Demo 15Wednesday, August 1, 12 15
  19. 19. Nullable Types Summary • null is a legitimate value, not a sin • No overhead (as opposed to Option) • Proper subtyping: ➡ List<String> is a List<String?> • At the expense of: file.getParent()!!.getName()!! 16Wednesday, August 1, 12 16
  20. 20. Annotations to The Rescue String String? JSR 305: Annotations for Software Defect Detection 17Wednesday, August 1, 12 17
  21. 21. Generics?! @NotNull doesnt help 18Wednesday, August 1, 12 18
  22. 22. More Use-Cases of @Kotlin 19Wednesday, August 1, 12 19
  23. 23. External Annotations 20Wednesday, August 1, 12 20
  24. 24. It Is Not So Bad • IDE aids annotating with quick fixes • Some annotations can be inferred automatically • Alternative: have a special kind of types for Java things 21Wednesday, August 1, 12 21
  25. 25. Statics Packages Class ObjectsWednesday, August 1, 12 22
  26. 26. Package-Level Code file1.kt foo/namespace.class file2.kt 23Wednesday, August 1, 12 23
  27. 27. Package-Level Code file1.kt foo/namespace.class Compiled From: file1.kt file2.kt 23Wednesday, August 1, 12 23
  28. 28. Package-Level Code file1.kt foo/namespace.class foo/namespace$file1.class from: file1.kt foo/namespace$file2.class file2.kt from: file2.kt 24Wednesday, August 1, 12 24
  29. 29. Package-Level Code file1.kt foo/namespace.class foo/namespace$file1.class from: Initialization Order?! file1.kt foo/namespace$file2.class file2.kt from: file2.kt 24Wednesday, August 1, 12 24
  30. 30. Kotlin Classes Have No StaticsWednesday, August 1, 12 25
  31. 31. Class Object Translation 26Wednesday, August 1, 12 26
  32. 32. Class Object Translation Only fields! 26Wednesday, August 1, 12 26
  33. 33. Resources • Docs: http://kotlin.jetbrains.org • Demo: http://kotlin-demo.jetbrains.com • Code: http://github.com/jetbrains/kotlin • Twitter: ➡ @project_kotlin ➡ @abreslav 27Wednesday, August 1, 12 27
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×