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

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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
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
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
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
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

[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