[JVMLS 12] Kotlin / Java Interop

  • 662 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
662
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
9
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. A Friend In Need Is a Friend Indeed Kotlin / Java Interop Andrey BreslavWednesday, August 1, 12 1
  • 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. Stuff • Apache 2 • IDE • Target ➡ IntelliJ ➡ JVM (1.6) ➡ Web Demo ➡ JavaScript * • Build ➡ Ant ➡ Maven 3 * PlannedWednesday, August 1, 12 3
  • 4. Outline 4Wednesday, August 1, 12 4
  • 5. Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces 4Wednesday, August 1, 12 4
  • 6. Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces • Fighting for Safety ➡ Nullable types ➡ Interaction with generics 4Wednesday, August 1, 12 4
  • 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. Making Existing Things Nicer Extensions Variance TricksWednesday, August 1, 12 5
  • 9. Extensions • Demo 6Wednesday, August 1, 12 6
  • 10. Collections & Variance Java: Kotlin: 7Wednesday, August 1, 12 7
  • 11. Declaration-Site Variance 8Wednesday, August 1, 12 8
  • 12. Translation Ø java.util.List 9Wednesday, August 1, 12 9
  • 13. Translation: Inheritance 10Wednesday, August 1, 12 10
  • 14. Translation: Variance 11Wednesday, August 1, 12 11
  • 15. Calling Java From Kotlin 12Wednesday, August 1, 12 12
  • 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. Fighting NPEs Nullable Types Annotating Java CodeWednesday, August 1, 12 14
  • 18. Nullable Types • Demo 15Wednesday, August 1, 12 15
  • 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. Annotations to The Rescue String String? JSR 305: Annotations for Software Defect Detection 17Wednesday, August 1, 12 17
  • 21. Generics?! @NotNull doesnt help 18Wednesday, August 1, 12 18
  • 22. More Use-Cases of @Kotlin 19Wednesday, August 1, 12 19
  • 23. External Annotations 20Wednesday, August 1, 12 20
  • 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. Statics Packages Class ObjectsWednesday, August 1, 12 22
  • 26. Package-Level Code file1.kt foo/namespace.class file2.kt 23Wednesday, August 1, 12 23
  • 27. Package-Level Code file1.kt foo/namespace.class Compiled From: file1.kt file2.kt 23Wednesday, August 1, 12 23
  • 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. 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. Kotlin Classes Have No StaticsWednesday, August 1, 12 25
  • 31. Class Object Translation 26Wednesday, August 1, 12 26
  • 32. Class Object Translation Only fields! 26Wednesday, August 1, 12 26
  • 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