javaone2012: kotlin: practical aspects of jvm language implementation
TRANSCRIPT
![Page 1: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/1.jpg)
Practical Aspects of JVM Language Implementation
Andrey Breslav
Kotlin: How Things Work
Tuesday, October 2, 12
![Page 2: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/2.jpg)
Why you should care• Language is an abstraction
➡ thus it leaks
• When something weird happens➡ you may need to "see through the Matrix"
2
abstraction
Tuesday, October 2, 12
![Page 3: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/3.jpg)
3
tetris is way too easywhen played this way
Tuesday, October 2, 12
![Page 4: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/4.jpg)
JVM & Its Languages
4
t1995
Scala,
Groovy, Closure, K
otlin...
Java
2012
What'spossible?
Tuesday, October 2, 12
![Page 5: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/5.jpg)
About Me
• Project lead of Kotlin ➡ at JetBrains since 2010
• EG member of JSR-335➡ Project Lambda
5
(not (RICH HICKEY))
Tuesday, October 2, 12
![Page 6: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/6.jpg)
Kotlin
6
Modern Language for Industry
• Static typing
• Readability
• Tool support
• Interoperability
• Smart compiler
➡ Less boilerplate
• Flexible abstractions
➡ Powerful libraries
Tuesday, October 2, 12
![Page 7: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/7.jpg)
Outline
• Extensions
• Bridges of All Sorts
• Types: Collections and Nulls
• Dreams... (maybe)
7
Tuesday, October 2, 12
![Page 8: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/8.jpg)
Extensions
• Live Demo➡ Extension syntax
➡ How it is compiled
➡ Multiple files in a package
8
Tuesday, October 2, 12
![Page 9: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/9.jpg)
Bridges
9
Tuesday, October 2, 12
![Page 10: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/10.jpg)
Bridges for Generics
10
(Lj/l/Object;)Lj/l/Object;
(I)I
(Lj/l/Object;)Lj/l/Object;
over
ride
s
"synthetic bridge method" (JLS)
Tuesday, October 2, 12
![Page 11: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/11.jpg)
Kotlin Brides & Primitives
11
1
foo(t: T) = t
1
1
foo(t: Int) = t
1
Java&
KotlinKotlin
Tuesday, October 2, 12
![Page 12: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/12.jpg)
Default Arguments
12
Tuesday, October 2, 12
![Page 13: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/13.jpg)
Masks for Defaults
13
foo(a, b) foo(a, b, mask: Int)if (mask & 1) a = 0if (mask & 2) b = 0foo(a, b)
Tuesday, October 2, 12
![Page 14: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/14.jpg)
Traits: Code in Interfaces
14
class Trait$Impl { static foo()V { println("Hi") }}
Tuesday, October 2, 12
![Page 15: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/15.jpg)
Trait Hierarchy
15
T1
T2
C
foo() { println() }
foo() { T2$Impl.foo()}
foo() { T1$Impl.foo() }
Tuesday, October 2, 12
![Page 16: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/16.jpg)
Summary
• Sometimes you need just one more method...
16
Tuesday, October 2, 12
![Page 17: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/17.jpg)
CollectionsHow Data-Compatible is Your Language?
Tuesday, October 2, 12
![Page 18: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/18.jpg)
Collections & Variance
18
Java:
Kotlin:
Tuesday, October 2, 12
![Page 19: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/19.jpg)
Kotlin's Collections
19
Tuesday, October 2, 12
![Page 20: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/20.jpg)
Declaration-Site Variance
20
Tuesday, October 2, 12
![Page 21: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/21.jpg)
Translation
21
Øjava.util.List
Tuesday, October 2, 12
![Page 22: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/22.jpg)
Translation: Inheritance
22
Tuesday, October 2, 12
![Page 23: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/23.jpg)
Translation: Variance
23
Tuesday, October 2, 12
![Page 24: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/24.jpg)
Calling Java From Kotlin
24
Tuesday, October 2, 12
![Page 25: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/25.jpg)
Summary
• Kotlin's collections➡ Better than Java's
➡ Still Compatible
25
Tuesday, October 2, 12
![Page 26: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/26.jpg)
Nullable Types
Tuesday, October 2, 12
![Page 27: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/27.jpg)
Demo
• Kotlin is null-safe
• Java code can be annotated for safe access
27
Tuesday, October 2, 12
![Page 28: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/28.jpg)
Talk Summary
• Languages are about tradeoffs
• Kotlin is cool :)
28
Tuesday, October 2, 12
![Page 29: JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation](https://reader034.vdocuments.site/reader034/viewer/2022052505/55517e98b4c90596028b468a/html5/thumbnails/29.jpg)
Kotlin Resources
• Docs: http://kotlin.jetbrains.org
• Demo: http://kotlin-demo.jetbrains.com
• Code: http://github.com/jetbrains/kotlin
• Twitter:➡ @project_kotlin
➡ @abreslav
29
Tuesday, October 2, 12