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

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

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