SlideShare a Scribd company logo
1 of 29
Download to read offline
Kotlin: How Things Work
                           Practical Aspects of JVM Language
                                      Implementation



                                    Andrey Breslav



Tuesday, October 2, 12
Why you should care
                     •   Language is an abstraction
                         ➡   thus it leaks




       abstraction



                     •   When something weird happens
                         ➡   you may need to "see through the Matrix"


                                                   2
Tuesday, October 2, 12
tetris is way too easy
                         when played this way

                                   3
Tuesday, October 2, 12
JVM & Its Languages

                                                                                What's
                                                                    i n...
                                                              otl
                                                         e , K                 possible?
                                                      sur
                                                   Clo
                                               vy,
                                          G roo
                                      ,
                                Sc ala
                         Java

                                                                                           t
     1995                                                               2012

                                               4
Tuesday, October 2, 12
About Me

              •          Project lead of Kotlin
                    ➡      at JetBrains since 2010

                                                         (not
                                                           (RICH HICKEY))

              •          EG member of JSR-335
                    ➡      Project Lambda




                                                     5
Tuesday, October 2, 12
Kotlin
                         Modern Language for Industry

                         •    Smart compiler              •   Static typing
                             ➡ Less boilerplate           •   Readability
                         •    Flexible abstractions       •   Tool support
                             ➡ Powerful libraries         •   Interoperability




                                                      6
Tuesday, October 2, 12
Outline
                     • Extensions
                     • Bridges of All Sorts
                     • Types: Collections and Nulls

                     • Dreams... (maybe)

                                        7
Tuesday, October 2, 12
Extensions
                     • Live Demo
                         ➡   Extension syntax
                         ➡   How it is compiled
                         ➡   Multiple files in a package




                                                  8
Tuesday, October 2, 12
Bridges




                          9
Tuesday, October 2, 12
Bridges for Generics
                              (Lj/l/Object;)Lj/l/Object;




                                                            overrides
                              (I)I


                              (Lj/l/Object;)Lj/l/Object;

                                      "synthetic bridge method" (JLS)



                             10
Tuesday, October 2, 12
Kotlin Brides & Primitives
    Java                 1               1
     &                                        Kotlin
   Kotlin

      foo(t: T) = t                foo(t: Int) = t



                         1               1

                              11
Tuesday, October 2, 12
Default Arguments




                            12
Tuesday, October 2, 12
Masks for Defaults



                         foo(a, b)   foo(a, b, mask: Int)
                                       if (mask & 1)
                                         a = 0
                                       if (mask & 2)
                                         b = 0
                                       foo(a, b)


                                     13
Tuesday, October 2, 12
Traits: Code in Interfaces
                                   class Trait$Impl {
                                     static foo()V {
                                       println("Hi")
                                     }
                                   }




                              14
Tuesday, October 2, 12
Trait Hierarchy
                         T1   foo() { println() }


                         T2   foo() { T1$Impl.foo() }


                         C    foo() {
                                T2$Impl.foo()
                              }
                                      15
Tuesday, October 2, 12
Summary
                     • Sometimes you need just one more
                         method...




                                       16
Tuesday, October 2, 12
Collections
                         How Data-Compatible is Your Language?




Tuesday, October 2, 12
Collections & Variance
   Java:




   Kotlin:



                             18
Tuesday, October 2, 12
Kotlin's Collections




                              19
Tuesday, October 2, 12
Declaration-Site Variance




                             20
Tuesday, October 2, 12
Translation

                                   Ø
                                   java.util.List




                              21
Tuesday, October 2, 12
Translation: Inheritance




                              22
Tuesday, October 2, 12
Translation: Variance




                              23
Tuesday, October 2, 12
Calling Java From Kotlin




                             24
Tuesday, October 2, 12
Summary
                     • Kotlin's collections
                         ➡   Better than Java's
                         ➡   Still Compatible




                                                  25
Tuesday, October 2, 12
Nullable Types



Tuesday, October 2, 12
Demo
                     • Kotlin is null-safe
                     • Java code can be annotated for safe
                         access




                                        27
Tuesday, October 2, 12
Talk Summary
                     • Languages are about tradeoffs
                     • Kotlin is cool :)




                                       28
Tuesday, October 2, 12
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

More Related Content

Viewers also liked

Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011
Andrey Breslav
 
Introduction to Kotlin: Brief and clear
Introduction to Kotlin: Brief and clearIntroduction to Kotlin: Brief and clear
Introduction to Kotlin: Brief and clear
Andrey Breslav
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
Andrzej Sitek
 
Who's More Functional: Kotlin, Groovy, Scala, or Java?
Who's More Functional: Kotlin, Groovy, Scala, or Java?Who's More Functional: Kotlin, Groovy, Scala, or Java?
Who's More Functional: Kotlin, Groovy, Scala, or Java?
Andrey Breslav
 

Viewers also liked (13)

Kotlin gets Reflection
Kotlin gets ReflectionKotlin gets Reflection
Kotlin gets Reflection
 
Language Design Trade-offs
Language Design Trade-offsLanguage Design Trade-offs
Language Design Trade-offs
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
 
Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011
 
Kotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexKotlin @ CSClub & Yandex
Kotlin @ CSClub & Yandex
 
Eval4j @ JVMLS 2014
Eval4j @ JVMLS 2014Eval4j @ JVMLS 2014
Eval4j @ JVMLS 2014
 
Flexible Types in Kotlin - JVMLS 2015
Flexible Types in Kotlin - JVMLS 2015Flexible Types in Kotlin - JVMLS 2015
Flexible Types in Kotlin - JVMLS 2015
 
Kotlin @ Devoxx 2011
Kotlin @ Devoxx 2011Kotlin @ Devoxx 2011
Kotlin @ Devoxx 2011
 
Introduction to Kotlin: Brief and clear
Introduction to Kotlin: Brief and clearIntroduction to Kotlin: Brief and clear
Introduction to Kotlin: Brief and clear
 
JVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in KotlinJVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in Kotlin
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
Who's More Functional: Kotlin, Groovy, Scala, or Java?
Who's More Functional: Kotlin, Groovy, Scala, or Java?Who's More Functional: Kotlin, Groovy, Scala, or Java?
Who's More Functional: Kotlin, Groovy, Scala, or Java?
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation

  • 1. Kotlin: How Things Work Practical Aspects of JVM Language Implementation Andrey Breslav Tuesday, October 2, 12
  • 2. Why you should care • Language is an abstraction ➡ thus it leaks abstraction • When something weird happens ➡ you may need to "see through the Matrix" 2 Tuesday, October 2, 12
  • 3. tetris is way too easy when played this way 3 Tuesday, October 2, 12
  • 4. JVM & Its Languages What's i n... otl e , K possible? sur Clo vy, G roo , Sc ala Java t 1995 2012 4 Tuesday, October 2, 12
  • 5. About Me • Project lead of Kotlin ➡ at JetBrains since 2010 (not (RICH HICKEY)) • EG member of JSR-335 ➡ Project Lambda 5 Tuesday, October 2, 12
  • 6. Kotlin Modern Language for Industry • Smart compiler • Static typing ➡ Less boilerplate • Readability • Flexible abstractions • Tool support ➡ Powerful libraries • Interoperability 6 Tuesday, October 2, 12
  • 7. Outline • Extensions • Bridges of All Sorts • Types: Collections and Nulls • Dreams... (maybe) 7 Tuesday, October 2, 12
  • 8. Extensions • Live Demo ➡ Extension syntax ➡ How it is compiled ➡ Multiple files in a package 8 Tuesday, October 2, 12
  • 9. Bridges 9 Tuesday, October 2, 12
  • 10. Bridges for Generics (Lj/l/Object;)Lj/l/Object; overrides (I)I (Lj/l/Object;)Lj/l/Object; "synthetic bridge method" (JLS) 10 Tuesday, October 2, 12
  • 11. Kotlin Brides & Primitives Java 1 1 & Kotlin Kotlin foo(t: T) = t foo(t: Int) = t 1 1 11 Tuesday, October 2, 12
  • 12. Default Arguments 12 Tuesday, October 2, 12
  • 13. Masks for Defaults foo(a, b) foo(a, b, mask: Int) if (mask & 1) a = 0 if (mask & 2) b = 0 foo(a, b) 13 Tuesday, October 2, 12
  • 14. Traits: Code in Interfaces class Trait$Impl { static foo()V { println("Hi") } } 14 Tuesday, October 2, 12
  • 15. Trait Hierarchy T1 foo() { println() } T2 foo() { T1$Impl.foo() } C foo() { T2$Impl.foo() } 15 Tuesday, October 2, 12
  • 16. Summary • Sometimes you need just one more method... 16 Tuesday, October 2, 12
  • 17. Collections How Data-Compatible is Your Language? Tuesday, October 2, 12
  • 18. Collections & Variance Java: Kotlin: 18 Tuesday, October 2, 12
  • 19. Kotlin's Collections 19 Tuesday, October 2, 12
  • 20. Declaration-Site Variance 20 Tuesday, October 2, 12
  • 21. Translation Ø java.util.List 21 Tuesday, October 2, 12
  • 22. Translation: Inheritance 22 Tuesday, October 2, 12
  • 23. Translation: Variance 23 Tuesday, October 2, 12
  • 24. Calling Java From Kotlin 24 Tuesday, October 2, 12
  • 25. Summary • Kotlin's collections ➡ Better than Java's ➡ Still Compatible 25 Tuesday, October 2, 12
  • 27. Demo • Kotlin is null-safe • Java code can be annotated for safe access 27 Tuesday, October 2, 12
  • 28. Talk Summary • Languages are about tradeoffs • Kotlin is cool :) 28 Tuesday, October 2, 12
  • 29. 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