SlideShare a Scribd company logo
1 of 33
Download to read offline
A Friend In Need Is a Friend Indeed

                          Kotlin / Java Interop

                                    Andrey Breslav




Wednesday, August 1, 12                                         1
Kotlin
                          Modern Language for Industry

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




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




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




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

               •    Fighting for Safety
                   ➡      Nullable types
                   ➡      Interaction with generics




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

               •    Fighting for Safety
                   ➡      Nullable types
                   ➡      Interaction with generics

               •    Statics
                   ➡      Packages
                   ➡      Class objects
                                                 4
Wednesday, August 1, 12                                      4
Making Existing
                           Things Nicer
                                Extensions
                              Variance Tricks




Wednesday, August 1, 12                         5
Extensions
               • Demo




                          6
Wednesday, August 1, 12       6
Collections & Variance
  Java:




  Kotlin:



                          7
Wednesday, August 1, 12              7
Declaration-Site Variance




                          8
Wednesday, August 1, 12                 8
Translation

                              Ø
                              java.util.List




                          9
Wednesday, August 1, 12                        9
Translation: Inheritance




                          10
Wednesday, August 1, 12                10
Translation: Variance




                          11
Wednesday, August 1, 12             11
Calling Java From Kotlin




                          12
Wednesday, 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


                                       13
Wednesday, August 1, 12                               13
Fighting NPEs
                               Nullable Types
                            Annotating Java Code




Wednesday, August 1, 12                            14
Nullable Types
               • Demo




                          15
Wednesday, 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()!!

                                               16
Wednesday, August 1, 12                                           16
Annotations to The Rescue

                                          String   String?




       JSR 305: Annotations for Software Defect Detection

                               17
Wednesday, August 1, 12                                      17
Generics?!


                               @NotNull
                                doesn't
                                 help




                          18
Wednesday, August 1, 12                   18
More Use-Cases of @Kotlin




                          19
Wednesday, August 1, 12                 19
External Annotations




                          20
Wednesday, 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


                                      21
Wednesday, August 1, 12                                      21
Statics
                            Packages
                          Class Objects




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




        file2.kt




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

                               Compiled From: file1.kt



        file2.kt




                          23
Wednesday, 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




                             24
Wednesday, 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




                                    24
Wednesday, August 1, 12                                                  24
Kotlin Classes
                          Have No Statics



Wednesday, August 1, 12                     25
Class Object Translation




                          26
Wednesday, August 1, 12                26
Class Object Translation

                               Only fields!




                          26
Wednesday, 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


                                        27
Wednesday, August 1, 12                                  27

More Related Content

Viewers also liked

JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation
JavaOne2012: Kotlin: Practical Aspects of JVM Language ImplementationJavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation
JavaOne2012: Kotlin: Practical Aspects of JVM Language ImplementationAndrey Breslav
 
Kotlin (Introduction for students)
Kotlin (Introduction for students)Kotlin (Introduction for students)
Kotlin (Introduction for students)Andrey Breslav
 
Language Design Trade-offs
Language Design Trade-offsLanguage Design Trade-offs
Language Design Trade-offsAndrey Breslav
 
Kotlin gets Reflection
Kotlin gets ReflectionKotlin gets Reflection
Kotlin gets ReflectionAndrey Breslav
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Andrey Breslav
 
Kotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexKotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexAndrey Breslav
 
Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011Andrey 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
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in actionCiro Rizzo
 
A brief introduction to Realm with Kotlin
A brief introduction to Realm with KotlinA brief introduction to Realm with Kotlin
A brief introduction to Realm with KotlinLeonardo YongUk Kim
 
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 (16)

JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation
JavaOne2012: Kotlin: Practical Aspects of JVM Language ImplementationJavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation
JavaOne2012: Kotlin: Practical Aspects of JVM Language Implementation
 
Kotlin (Introduction for students)
Kotlin (Introduction for students)Kotlin (Introduction for students)
Kotlin (Introduction for students)
 
Language Design Trade-offs
Language Design Trade-offsLanguage Design Trade-offs
Language Design Trade-offs
 
Kotlin gets Reflection
Kotlin gets ReflectionKotlin gets Reflection
Kotlin gets Reflection
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
 
Eval4j @ JVMLS 2014
Eval4j @ JVMLS 2014Eval4j @ JVMLS 2014
Eval4j @ JVMLS 2014
 
Kotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexKotlin @ CSClub & Yandex
Kotlin @ CSClub & Yandex
 
Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011Kotlin @ StrangeLoop 2011
Kotlin @ StrangeLoop 2011
 
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
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
 
A brief introduction to Realm with Kotlin
A brief introduction to Realm with KotlinA brief introduction to Realm with Kotlin
A brief introduction to Realm with Kotlin
 
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
 

Similar to [JVMLS 12] Kotlin / Java Interop

Enterprise javascriptsession1
Enterprise javascriptsession1Enterprise javascriptsession1
Enterprise javascriptsession1Troy Miles
 
Performance for Product Developers
Performance for Product DevelopersPerformance for Product Developers
Performance for Product DevelopersMatthew Wilkes
 
Java EE and Google App Engine
Java EE and Google App EngineJava EE and Google App Engine
Java EE and Google App EngineArun Gupta
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事Wen-Tien Chang
 
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012kennethaliu
 
Play concurrency
Play concurrencyPlay concurrency
Play concurrencyJustin Long
 
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse LibraJavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse LibraMurat Yener
 
Pinterest arch summit august 2012 - scaling pinterest
Pinterest arch summit   august 2012 - scaling pinterestPinterest arch summit   august 2012 - scaling pinterest
Pinterest arch summit august 2012 - scaling pinterestdrewz lin
 
static ABAP code analyzers
static ABAP code analyzersstatic ABAP code analyzers
static ABAP code analyzersMarkus Theilen
 
Hadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionHadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionClaudio Martella
 
Designing Puppet: Roles/Profiles Pattern
Designing Puppet: Roles/Profiles PatternDesigning Puppet: Roles/Profiles Pattern
Designing Puppet: Roles/Profiles PatternPuppet
 
2012 Q4 Cooperative Support for CAS Update
2012 Q4 Cooperative Support for CAS Update2012 Q4 Cooperative Support for CAS Update
2012 Q4 Cooperative Support for CAS UpdateAndrew Petro
 
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter LedbrookJava Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter LedbrookJAX London
 
Software Libraries And Numbers
Software Libraries And NumbersSoftware Libraries And Numbers
Software Libraries And NumbersRobert Reiz
 
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic ConceptsMorning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic ConceptsMongoDB
 

Similar to [JVMLS 12] Kotlin / Java Interop (20)

Enterprise javascriptsession1
Enterprise javascriptsession1Enterprise javascriptsession1
Enterprise javascriptsession1
 
Performance for Product Developers
Performance for Product DevelopersPerformance for Product Developers
Performance for Product Developers
 
Java EE and Google App Engine
Java EE and Google App EngineJava EE and Google App Engine
Java EE and Google App Engine
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事
 
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Play concurrency
Play concurrencyPlay concurrency
Play concurrency
 
Iwmn architecture
Iwmn architectureIwmn architecture
Iwmn architecture
 
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse LibraJavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
JavaOne 2012, OSGi for the Earthlings: Meet Eclipse Libra
 
Pinterest arch summit august 2012 - scaling pinterest
Pinterest arch summit   august 2012 - scaling pinterestPinterest arch summit   august 2012 - scaling pinterest
Pinterest arch summit august 2012 - scaling pinterest
 
static ABAP code analyzers
static ABAP code analyzersstatic ABAP code analyzers
static ABAP code analyzers
 
Hadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionHadoop: A Hands-on Introduction
Hadoop: A Hands-on Introduction
 
Designing Puppet: Roles/Profiles Pattern
Designing Puppet: Roles/Profiles PatternDesigning Puppet: Roles/Profiles Pattern
Designing Puppet: Roles/Profiles Pattern
 
Stardog talk-dc-march-17
Stardog talk-dc-march-17Stardog talk-dc-march-17
Stardog talk-dc-march-17
 
Extending rails
Extending railsExtending rails
Extending rails
 
2012 Q4 Cooperative Support for CAS Update
2012 Q4 Cooperative Support for CAS Update2012 Q4 Cooperative Support for CAS Update
2012 Q4 Cooperative Support for CAS Update
 
Devoxx Java Social and Agorava
Devoxx Java Social and AgoravaDevoxx Java Social and Agorava
Devoxx Java Social and Agorava
 
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter LedbrookJava Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
 
Software Libraries And Numbers
Software Libraries And NumbersSoftware Libraries And Numbers
Software Libraries And Numbers
 
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic ConceptsMorning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

[JVMLS 12] Kotlin / Java Interop

  • 1. A Friend In Need Is a Friend Indeed Kotlin / Java Interop Andrey Breslav Wednesday, August 1, 12 1
  • 2. Kotlin Modern Language for Industry • Smart compiler • Static typing ➡ Less boilerplate • Readability • Flexible abstractions • Tool support ➡ Powerful libraries • Interoperability 2 Wednesday, August 1, 12 2
  • 3. Stuff • Apache 2 • IDE • Target ➡ IntelliJ ➡ JVM (1.6) ➡ Web Demo ➡ JavaScript * • Build ➡ Ant ➡ Maven 3 * Planned Wednesday, August 1, 12 3
  • 4. Outline 4 Wednesday, August 1, 12 4
  • 5. Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces 4 Wednesday, August 1, 12 4
  • 6. Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces • Fighting for Safety ➡ Nullable types ➡ Interaction with generics 4 Wednesday, August 1, 12 4
  • 7. Outline • Enhancing Existing APIs ➡ Extensions ➡ Splitting Collections Interfaces • Fighting for Safety ➡ Nullable types ➡ Interaction with generics • Statics ➡ Packages ➡ Class objects 4 Wednesday, August 1, 12 4
  • 8. Making Existing Things Nicer Extensions Variance Tricks Wednesday, August 1, 12 5
  • 9. Extensions • Demo 6 Wednesday, August 1, 12 6
  • 10. Collections & Variance Java: Kotlin: 7 Wednesday, August 1, 12 7
  • 11. Declaration-Site Variance 8 Wednesday, August 1, 12 8
  • 12. Translation Ø java.util.List 9 Wednesday, August 1, 12 9
  • 13. Translation: Inheritance 10 Wednesday, August 1, 12 10
  • 14. Translation: Variance 11 Wednesday, August 1, 12 11
  • 15. Calling Java From Kotlin 12 Wednesday, August 1, 12 12
  • 16. 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 13 Wednesday, August 1, 12 13
  • 17. Fighting NPEs Nullable Types Annotating Java Code Wednesday, August 1, 12 14
  • 18. Nullable Types • Demo 15 Wednesday, August 1, 12 15
  • 19. 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()!! 16 Wednesday, August 1, 12 16
  • 20. Annotations to The Rescue String String? JSR 305: Annotations for Software Defect Detection 17 Wednesday, August 1, 12 17
  • 21. Generics?! @NotNull doesn't help 18 Wednesday, August 1, 12 18
  • 22. More Use-Cases of @Kotlin 19 Wednesday, August 1, 12 19
  • 23. External Annotations 20 Wednesday, August 1, 12 20
  • 24. 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 21 Wednesday, August 1, 12 21
  • 25. Statics Packages Class Objects Wednesday, August 1, 12 22
  • 26. Package-Level Code file1.kt foo/namespace.class file2.kt 23 Wednesday, August 1, 12 23
  • 27. Package-Level Code file1.kt foo/namespace.class Compiled From: file1.kt file2.kt 23 Wednesday, August 1, 12 23
  • 28. Package-Level Code file1.kt foo/namespace.class foo/namespace$file1.class from: file1.kt foo/namespace$file2.class file2.kt from: file2.kt 24 Wednesday, August 1, 12 24
  • 29. 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 24 Wednesday, August 1, 12 24
  • 30. Kotlin Classes Have No Statics Wednesday, August 1, 12 25
  • 31. Class Object Translation 26 Wednesday, August 1, 12 26
  • 32. Class Object Translation Only fields! 26 Wednesday, August 1, 12 26
  • 33. Resources • Docs: http://kotlin.jetbrains.org • Demo: http://kotlin-demo.jetbrains.com • Code: http://github.com/jetbrains/kotlin • Twitter: ➡ @project_kotlin ➡ @abreslav 27 Wednesday, August 1, 12 27