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 gets Reflection
Kotlin gets ReflectionKotlin gets Reflection
Kotlin gets ReflectionAndrey Breslav
 
Language Design Trade-offs
Language Design Trade-offsLanguage Design Trade-offs
Language Design Trade-offsAndrey Breslav
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Andrey Breslav
 
Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011Andrey Breslav
 
Kotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexKotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexAndrey Breslav
 
Flexible Types in Kotlin - JVMLS 2015
Flexible Types in Kotlin - JVMLS 2015Flexible Types in Kotlin - JVMLS 2015
Flexible Types in Kotlin - JVMLS 2015Andrey Breslav
 
Introduction to Kotlin: Brief and clear
Introduction to Kotlin: Brief and clearIntroduction to Kotlin: Brief and clear
Introduction to Kotlin: Brief and clearAndrey Breslav
 
JVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in KotlinJVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in KotlinAndrey Breslav
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej 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
 
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) Datagreenwop
 

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

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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 FMESafe Software
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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 WoodJuan lago vázquez
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

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