[JVMLS 12] Kotlin / Java Interop

50 %
50 %
Information about [JVMLS 12] Kotlin / Java Interop
Technology

Published on August 1, 2012

Author: abreslav

Source: slideshare.net

A Friend In Need Is a Friend Indeed Kotlin / Java Interop Andrey BreslavWednesday, August 1, 12 1

Kotlin Modern Language for Industry • Smart compiler • Static typing ➡ Less boilerplate • Readability • Flexible abstractions • Tool support ➡ Powerful libraries • Interoperability 2Wednesday, August 1, 12 2

Stuff • Apache 2 • IDE • Target ➡ IntelliJ ➡ JVM (1.6) ➡ Web Demo ➡ JavaScript * • Build ➡ Ant ➡ Maven 3 * PlannedWednesday, August 1, 12 3

Outline 4Wednesday, August 1, 12 4

Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces 4Wednesday, August 1, 12 4

Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces • Fighting for Safety ➡ Nullable types ➡ Interaction with generics 4Wednesday, August 1, 12 4

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

Making Existing Things Nicer Extensions Variance TricksWednesday, August 1, 12 5

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, August 1, 12 9

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 • Make them variant for Kotlin • At the expense of some unsoundness around the edges 13Wednesday, August 1, 12 13

Fighting NPEs Nullable Types Annotating Java CodeWednesday, August 1, 12 14

Nullable Types • Demo 15Wednesday, August 1, 12 15

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

Annotations to The Rescue String String? JSR 305: Annotations for Software Defect Detection 17Wednesday, August 1, 12 17

Generics?! @NotNull doesnt help 18Wednesday, August 1, 12 18

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 automatically • Alternative: have a special kind of types for Java things 21Wednesday, August 1, 12 21

Statics Packages Class ObjectsWednesday, August 1, 12 22

Package-Level Code file1.kt foo/namespace.class file2.kt 23Wednesday, August 1, 12 23

Package-Level Code file1.kt foo/namespace.class Compiled From: file1.kt file2.kt 23Wednesday, August 1, 12 23

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

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

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 26

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

Add a comment

Related presentations

Related pages

Java Interop - Kotlin

Edit Page Java Interop. Kotlin is designed with Java Interoperability in mind. Existing Java code can be called from Kotlin in a natural way, and Kotlin ...
Read more

JavaScript Interop | Kotlin Blog

In order for this code to work however, we still need to declare jQuery as dynamic, and mark it with the corresponding native equivalent for Kotlin to call
Read more

Kotlin / Java Interop

Kotlin / Java Interop Andrey Breslav A Friend In Need Is a Friend Indeed Wednesday, August 1, 12 1
Read more

Reference - Kotlin

Java Interop. Tools. ... Kotlin and OSGi. FAQ. FAQ. Comparison to Java. Comparison to Scala. Full Kotlin Reference. ... Full coverage of the Kotlin syntax ...
Read more

Java interoperability - Kotlin - Confluence

Java generics in Kotlin. Kotlin's generics are a little different from Java's (see Generics). When importing Java types to Kotlin we perform some conversions:
Read more

Improving Java Interop: Top-Level Functions and Properties ...

Kotlin has had top-level functions and properties from day one. They are very convenient in many cases: from basic utilities to extensions for standard APIs.
Read more

javascript - Kotlin JS and GWT interop - Stack Overflow

Kotlin JS compiler emits Java Script code from Kotlin code. GWT emits Java Script code from Java source code. Is it possible in easy way to connect JS ...
Read more

Description of the interop with Java reflection by ...

Description of the interop with Java reflection #157. ... ## Calling Kotlin code from Java: Kotlin code can be called from Java easily. Toggle all file notes.
Read more

interop - How to use Kotlin anonymous classes as arguments ...

I am setting up the interop layer for this ThreeJS class and the constructor of the class takes in a object which is used to set the properties.
Read more