SlideShare uma empresa Scribd logo
1 de 75
Baixar para ler offline
The Kotlin
               Programming Language

                             Andrey Breslav




Monday, September 19, 2011
What is Kotlin?




                             2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed




                                                2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed
                   •         object-oriented




                                                2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed
                   •         object-oriented
                   •         JVM-targeted




                                                2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed
                   •         object-oriented
                   •         JVM-targeted
                   •         general-purpose




                                                2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed
                   •         object-oriented
                   •         JVM-targeted
                   •         general-purpose
                   •         programming language




                                                    2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed
                   •         object-oriented
                   •         JVM-targeted
                   •         general-purpose
                   •         programming language
                   •         developed by JetBrains




                                                      2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed
                   •         object-oriented
                   •         JVM-targeted
                   •         general-purpose
                   •         programming language
                   •         developed by JetBrains
                         ➡      intended for industrial use




                                                              2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed
                   •         object-oriented
                   •         JVM-targeted
                   •         general-purpose
                   •         programming language
                   •         developed by JetBrains
                         ➡      intended for industrial use



                   •         Docs available today



                                                              2
Monday, September 19, 2011
What is Kotlin?
                   •         Statically typed
                   •         object-oriented
                   •         JVM-targeted
                   •         general-purpose
                   •         programming language
                   •         developed by JetBrains
                         ➡      intended for industrial use



                   •         Docs available today
                   •         Public beta is planned for the end of 2011

                                                              2
Monday, September 19, 2011
Goal-wise...




                              3
Monday, September 19, 2011
Goal-wise...
                   • Number of research papers we are
                             planning to publish on Kotlin is




                                               3
Monday, September 19, 2011
Goal-wise...
                   • Number of research papers we are
                             planning to publish on Kotlin is
                         ➡    Zero




                                               3
Monday, September 19, 2011
Goal-wise...
                   • Number of research papers we are
                             planning to publish on Kotlin is
                         ➡    Zero
                         ➡    ... or really close to that




                                                   3
Monday, September 19, 2011
Outline
                   • Motivation
                   • Feature overview
                   • Basic syntax
                   • Classes and Types
                   • Higher-order functions
                   • Type-safe Groovy-style Builders
                                      4
Monday, September 19, 2011
Motivation




                             5
Monday, September 19, 2011
Motivation
                   •         Why a new language?




                                                   5
Monday, September 19, 2011
Motivation
                   •         Why a new language?
                         ➡     We are not satisfied with the existing ones
                         ➡     And we have had a close look at many of them over 10 years




                                                      5
Monday, September 19, 2011
Motivation
                   •         Why a new language?
                         ➡     We are not satisfied with the existing ones
                         ➡     And we have had a close look at many of them over 10 years

                   •         Design goals




                                                      5
Monday, September 19, 2011
Motivation
                   •         Why a new language?
                         ➡     We are not satisfied with the existing ones
                         ➡     And we have had a close look at many of them over 10 years

                   •         Design goals
                         ➡     Full Java interoperability




                                                      5
Monday, September 19, 2011
Motivation
                   •         Why a new language?
                         ➡     We are not satisfied with the existing ones
                         ➡     And we have had a close look at many of them over 10 years

                   •         Design goals
                         ➡     Full Java interoperability
                         ➡     Compiles as fast as Java




                                                      5
Monday, September 19, 2011
Motivation
                   •         Why a new language?
                         ➡     We are not satisfied with the existing ones
                         ➡     And we have had a close look at many of them over 10 years

                   •         Design goals
                         ➡     Full Java interoperability
                         ➡     Compiles as fast as Java
                         ➡     Safer than Java




                                                      5
Monday, September 19, 2011
Motivation
                   •         Why a new language?
                         ➡     We are not satisfied with the existing ones
                         ➡     And we have had a close look at many of them over 10 years

                   •         Design goals
                         ➡     Full Java interoperability
                         ➡     Compiles as fast as Java
                         ➡     Safer than Java
                         ➡     More concise than Java


                                                      5
Monday, September 19, 2011
Motivation
                   •         Why a new language?
                         ➡     We are not satisfied with the existing ones
                         ➡     And we have had a close look at many of them over 10 years

                   •         Design goals
                         ➡     Full Java interoperability
                         ➡     Compiles as fast as Java
                         ➡     Safer than Java
                         ➡     More concise than Java
                         ➡     Way simpler than Scala
                                                      5
Monday, September 19, 2011
Feature overview




                             6
Monday, September 19, 2011
Feature overview
                   •         Language features




                                                 6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees




                                                                6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")




                                                                 6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation




                                                                  6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)




                                                                  6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)
                         ➡      Reified generics




                                                                  6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)
                         ➡      Reified generics
                         ➡      Declaration-site variance & "Type projections"




                                                                  6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)
                         ➡      Reified generics
                         ➡      Declaration-site variance & "Type projections"
                         ➡      Extension functions




                                                                  6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)
                         ➡      Reified generics
                         ➡      Declaration-site variance & "Type projections"
                         ➡      Extension functions
                         ➡      Modules and Build infrastructure




                                                                   6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)
                         ➡      Reified generics
                         ➡      Declaration-site variance & "Type projections"
                         ➡      Extension functions
                         ➡      Modules and Build infrastructure
                         ➡      Inline-functions (zero-overhead closures)




                                                                   6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)
                         ➡      Reified generics
                         ➡      Declaration-site variance & "Type projections"
                         ➡      Extension functions
                         ➡      Modules and Build infrastructure
                         ➡      Inline-functions (zero-overhead closures)
                         ➡      Pattern matching




                                                                   6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)
                         ➡      Reified generics
                         ➡      Declaration-site variance & "Type projections"
                         ➡      Extension functions
                         ➡      Modules and Build infrastructure
                         ➡      Inline-functions (zero-overhead closures)
                         ➡      Pattern matching
                         ➡      ...



                                                                   6
Monday, September 19, 2011
Feature overview
                   •         Language features
                         ➡      Static null-safety guarantees
                         ➡      Higher-order functions ("closures")
                         ➡      Traits & First-class delegation
                         ➡      Properties (no fields)
                         ➡      Reified generics
                         ➡      Declaration-site variance & "Type projections"
                         ➡      Extension functions
                         ➡      Modules and Build infrastructure
                         ➡      Inline-functions (zero-overhead closures)
                         ➡      Pattern matching
                         ➡      ...

                   •         Full-featured IDE by JetBrains from the very beginning

                                                                   6
Monday, September 19, 2011
Code examples
                   •         Functions
                   •         Java interoperability
                   •         String templates
                   •         Local variables
                   •         Type inference
                   •         Extension functions and properties
                   •         Null-safety

                                                     7
Monday, September 19, 2011
Hello, world!
               namespace hello

               fun main(args : Array<String>) : Unit {
                 println("Hello, world!")
               }

               fun println(message : String) {
                   System.out?.println(message)
               }




                                          8
Monday, September 19, 2011
Hello, <names>!
               fun main(args : Array<String>) {
                   var names : String = ""

                        for (i in args.indices) {
                            names += args[i]
                            if (i + 1 < args.size)
                                names += ", "
                        }

                        println("Hello, $names!")
               }

               val Array<*>.indices : Iterable<Int>
                 get() = IntRange<Int>(0, size - 1)




                                               9
Monday, September 19, 2011
Hello, <names>! (Faster version)
               fun main(args : Array<String>) {
                   val names = StringBuilder()

                        for (i in args.indices) {
                            names += args[i]
                            if (i + 1 < args.size)
                                names += ", "
                        }

                        println("Hello, $names!")
               }

               fun StringBuilder.plusAssign(s : String) {
                   this.append(s)
               }



                                               10
Monday, September 19, 2011
Hello, <names>! (Realistic version)
               fun main(args : Array<String>) {
                   println("Hello, ${args.join(", ")}!")
               }

               fun <T> Iterable<T>.join(separator : String) : String {
                   val names = StringBuilder()
                   forit (this) {
                       names += it.next()
                       if (it.hasNext())
                           names += separator
                   }
                   return names.toString()
               }




                                          11
Monday, September 19, 2011
join() and forit()
               fun <T> Iterable<T>.join(separator : String) : String {
                   val names = StringBuilder()
                   forit (this) {
                       names += it.next()
                       if (it.hasNext())
                           names += separator
                   }
                   return names.toString()
               }


               fun <T> forit(col : Iterable<T>, f : fun(Iterator<T>) : Unit) {
                   val it = col.iterator()
                   while (it.hasNext()) {
                       f(it)
                   }
               }

                                           12
Monday, September 19, 2011
Null-safety
               fun parseInt(s      : String) : Int? {
                   try {
                       return      Integer.parseInt(s)
                   } catch (e      : NumberFormatException) {
                       return      null
                   }
               }

               fun main(args : Array<String>) {
                   val x = parseInt("123")
                   val y = parseInt("Hello")
                   print(x?.times(2))        // Can't say: print(x * 2)

                        if (x != null) {
                            print(x * 2)
                        }
               }
                                               13
Monday, September 19, 2011
Types
                                                         Syntax

                                       Class types                    List<Foo>

                                    Nullable types                      Foo?

                                    Function types                fun (Int) : String

                                       Tuple types                (Double, Double)

                                          Self type                     This

                                                      Special types

                                              Top                       Any?

                                          Bottom                       Nothing

                        No meaningful return value                      Unit

                                                           14
Monday, September 19, 2011
Mapping to Java types
                              Kotlin   GEN    Java     LOAD      Kotlin
                              Any            Object              Any?
                              Unit            void               Unit
                              Int             int                 Int
                              Int?           Integer             Int?
                             String          String             String?
                         Array<Foo>          Foo[]            Array<Foo?>?
                         Array<Int>          int[]            Array<Int>?
                             Nothing           -                   -
                              Foo             Foo                Foo?


                                               15
Monday, September 19, 2011
Automatic casts and When
               fun foo(obj : Any?) {
                   if (obj is String) {
                     obj.get(0)
                   }
                   when (obj) {
                       is String => obj.get(0)
                       is Int => obj.plus(1)
                       !is Boolean => null
                   }
               }




                                          16
Monday, September 19, 2011
More on when-expressions
               fun bar(x : Int) {
                   when (x) {
                       0 => "Zero"
                       1, 2, 3 => "1, 2 or 3"
                       x + 1 => "Really strange"
                       in 10..100 => "In range"
                       !in 100..1000 => "Out of range"
                   }
               }




                                          17
Monday, September 19, 2011
Classes
                        open class Parent(p : Bar) {
                            open fun foo() {}
                            fun bar() {}
                        }

                        class Child(p : Bar) : Parent(p) {
                            override fun foo() {}
                        }


                   • Any is the default supertype
                   • Constructors must initialize supertypes
                   • Final by default, explicit override annotations

                                                18
Monday, September 19, 2011
Traits
               trait T1 : Class1, OtherTrait {
                    // No state
               }


               class Foo(p : Bar) : Class1(p), T1, T2 {
                 ...
               }


               class Decorator(p : T2) : Class2, T2 by p {
                    ...
               }


                                           19
Monday, September 19, 2011
Disambiguation
               trait A {
                    fun foo() : Int = 1 // open by default
               }


               open class B() {
                    open fun foo() : Int = 2
               }


               class C() : B(), A {
                    override fun foo() = super<A>.foo()
               }



                                               20
Monday, September 19, 2011
First-class functions
                   •         Functions
                         ➡     fun f(p : Int) : String

                   •         Function types
                         ➡     fun (p : Int) : String
                         ➡     fun (Int) : String

                   •         Function literals
                         ➡     {p => p.toString()}
                         ➡     {(p : Int) => p.toString()}
                         ➡     {(p : Int) : String => p.toString()}


                                                    21
Monday, September 19, 2011
Higher-order functions
                  fun <T> filter(
                            c : Iterable<T>,
                            f : fun(T) : Boolean) : Iterable<T>

               • filter(list,                 {s => s.length < 3})
                         ➡   Sugar: last function literal argument
                             ✦   filter(list) {s => s.length < 3}
                         ➡   Sugar: one-parameter function literal
                             ✦   filter(list) { it.length < 3 }


                                                 22
Monday, September 19, 2011
Infix function calls: "LINQ"
                  a.contains(b)

                  // is the same as

                  a contains b



                  users

                             filter { it hasPrivilege WRITE }

                             map { it => it.fullName }

                             orderBy { lastName }


                                                23
Monday, September 19, 2011
Lock example (I)
               myLock.lock()
               try {
                    // Do something
               }
               finally {
                    myLock.unlock()
               }




                                      24
Monday, September 19, 2011
Lock example (II)

               lock(myLock) {
                    // Do something
               }




               fun lock(l : Lock, body : fun () : Unit)


                                      25
Monday, September 19, 2011
Lock example (III)
               inline fun lock(l : Lock, body : fun () : Unit) {
                    myLock.lock()
                    try {
                         body()
                    }
                    finally {
                         myLock.unlock()
                    }
               }


                                           26
Monday, September 19, 2011
Extension functions
                   •         Functions
                         ➡     fun Foo.f(p : Int) : String

                   •         Function types
                         ➡     fun Foo.(p : Int) : String
                         ➡     fun Foo.(Int) : String

                   •         Function literals
                         ➡     {Foo.(p : Int) => this.toString()}
                         ➡     {Foo.(p : Int) : String => this.toString()}



                                                 27
Monday, September 19, 2011
Builders in Groovy
               html {
                     head {
                         title "XML encoding with Groovy"
                     }
                     body {
                         h1 "XML encoding with Groovy"
                         p "this format can be used as an alternative markup to XML"


                         /* an element with attributes and text content */
                         ahref:'http://groovy.codehaus.org' ["Groovy"]
                     }
               }



                                                   28
Monday, September 19, 2011
Builders in Kotlin
               html {
                     head {
                         title { +"XML encoding with Kotlin" }
                     }
                     body {
                         h1 { +"XML encoding with Kotlin" }
                         p { +"this format is now type-safe" }


                         /* an element with attributes and text content */
                         a(href="http://jetbrains.com/kotlin") { +"Kotlin" }
                     }
               }



                                                   29
Monday, September 19, 2011
Builders: Implementation (I)
                   •         Function definition

                             fun html(init : fun HTML.() : Unit) : HTML {
                               val html = HTML()
                               html.init()
                               return html
                             }
                   •         Usage

                             html {
                               this.head { ... }
                             }


                                                   30
Monday, September 19, 2011
Builders: Implementation (II)
                   •         Function definition

                             fun html(init : fun HTML.() : Unit) : HTML {
                               val html = HTML()
                               html.init()
                               return html
                             }
                   •         Usage

                             html {
                               head { ... }
                             }


                                                   31
Monday, September 19, 2011
Builders: Implementation (III)
               abstract class Tag(val name : String) : Element {
                   val children = ArrayList<Element>()
                   val attributes = HashMap<String, String>()
               }

               abstract class TagWithText(name : String) : Tag(name) {
                   fun String.plus() {
                     children.add(TextElement(this))
                   }
               }

               class HTML() : TagWithText("html") {
                   fun head(init : fun Head.() : Unit) { }
                   fun body(init : fun Body.() : Unit) { }
               }



                                          32
Monday, September 19, 2011
Builders in Kotlin
               html {
                     head {
                         title { +"XML encoding with Kotlin" }
                     }
                     body {
                         h1 { +"XML encoding with Kotlin" }
                         p { +"this format is now type-safe" }


                         /* an element with attributes and text content */
                         a(href="http://jetbrains.com/kotlin") { +"Kotlin" }
                     }
               }



                                                   33
Monday, September 19, 2011
Generics: Invariance
               class List<T> {
                     fun add(t : T)
                     fun get(index : Int) : T
               }


               val ints = List<Int>()
               val anys : List<Any> = ints
               anys.add("1") // Cause of the problem
               val i : Int = ints.get(0) // !!!
                                        34
Monday, September 19, 2011
Generics: Invariance
               class List<T> {
                     fun add(t : T)
                     fun get(index : Int) : T
               }


               val ints = List<Int>()
               val anys : List<Any> = ints
               anys.add("1") // Cause of the problem
               val i : Int = ints.get(0) // !!!
                                        34
Monday, September 19, 2011
Generics: Declaration-site variance
               class List<T> {           List<Int> >:< List<Any>
                   fun add(t : T)        val ints = List<Int>()
                   fun get() : T         val anys : List<Any> = ints
               }




               class Producer<out T> {   val ints = Producer<Int>()
                   fun get() : T         val anys : Producer<Any> = ints
               }


               class Consumer<in T> {    val anys = Consumer<Any>()
                   fun add(t : T)        val ints : Consumer<Int> = anys
               }



                                            35
Monday, September 19, 2011
Generics: Declaration-site variance
               class List<T> {           List<Int> >:< List<Any>
                   fun add(t : T)        val ints = List<Int>()
                   fun get() : T         val anys : List<Any> = ints
               }




               class Producer<out T> {   val ints = Producer<Int>()
                   fun get() : T         val anys : Producer<Any> = ints
               }


               class Consumer<in T> {    val anys = Consumer<Any>()
                   fun add(t : T)        val ints : Consumer<Int> = anys
               }



                                            35
Monday, September 19, 2011
Generics: Declaration-site variance
               class List<T> {           List<Int> >:< List<Any>
                   fun add(t : T)        val ints = List<Int>()
                   fun get() : T         val anys : List<Any> = ints
               }




               class Producer<out T> {   val ints = Producer<Int>()
                   fun get() : T         val anys : Producer<Any> = ints
               }


               class Consumer<in T> {    val anys = Consumer<Any>()
                   fun add(t : T)        val ints : Consumer<Int> = anys
               }



                                            35
Monday, September 19, 2011
Generics: Use-site variance
               val ints = List<Int>()
               val anysOut : List<out Any> = ints
               anysOut.add("1") // Not available
               val i : Int = ints.get() // No problem




                                    36
Monday, September 19, 2011
Generics: Use-site variance
               val ints = List<Int>()
               val anysOut : List<out Any> = ints
               anysOut.add("1") // Not available
               val i : Int = ints.get() // No problem

               val anys = List<Any>()
               val intsIn : List<in Int> = anys
               intsIn.add(0)
               val obj = intsIn.get() // : Any?

                                    36
Monday, September 19, 2011
Reified generics
                   • Type information in retained at runtime
                         ➡   foo is List<T>
                         ➡   Array<T>(3)
                         ➡   T.create()

                   • Java types are still erased
                         ➡   foo is java.util.List<*>



                                           37
Monday, September 19, 2011
Resources
                   • Documentation:
                         ➡   http://jetbrains.com/kotlin

                   • Blog:
                         ➡   http://blog.jetbrains.com/kotlin

                   • Twitter:
                         ➡   @project_kotlin
                         ➡   @abreslav

                                                 38
Monday, September 19, 2011

Mais conteúdo relacionado

Destaque

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
 
[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java InteropAndrey Breslav
 
Kotlin gets Reflection
Kotlin gets ReflectionKotlin gets Reflection
Kotlin gets ReflectionAndrey Breslav
 
Kotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexKotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexAndrey Breslav
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 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»
Светлана Исакова «Язык Kotlin»Светлана Исакова «Язык Kotlin»
Светлана Исакова «Язык Kotlin»e-Legion
 
Be More Productive with Kotlin
Be More Productive with KotlinBe More Productive with Kotlin
Be More Productive with KotlinBrandon Wever
 
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
 
Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...
Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...
Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...Codemotion
 

Destaque (16)

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
 
[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop
 
Kotlin gets Reflection
Kotlin gets ReflectionKotlin gets Reflection
Kotlin gets Reflection
 
Kotlin @ CSClub & Yandex
Kotlin @ CSClub & YandexKotlin @ CSClub & Yandex
Kotlin @ CSClub & Yandex
 
Eval4j @ JVMLS 2014
Eval4j @ JVMLS 2014Eval4j @ JVMLS 2014
Eval4j @ JVMLS 2014
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 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»
Светлана Исакова «Язык Kotlin»Светлана Исакова «Язык Kotlin»
Светлана Исакова «Язык Kotlin»
 
Be More Productive with Kotlin
Be More Productive with KotlinBe More Productive with Kotlin
Be More Productive 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
 
Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...
Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...
Functional Reactive Programming with Kotlin on Android - Giorgio Natili - Cod...
 

Semelhante a Kotlin @ StrangeLoop 2011

DCI - Data, Context and Interaction @ Jug Lugano May 2011
DCI - Data, Context and Interaction @ Jug Lugano May 2011 DCI - Data, Context and Interaction @ Jug Lugano May 2011
DCI - Data, Context and Interaction @ Jug Lugano May 2011 Fabrizio Giudici
 
Building Languages for the JVM - StarTechConf 2011
Building Languages for the JVM - StarTechConf 2011Building Languages for the JVM - StarTechConf 2011
Building Languages for the JVM - StarTechConf 2011Charles Nutter
 
Kotlin vs Java-A Comparison for Application Development Projects.pdf
Kotlin vs Java-A Comparison for Application Development Projects.pdfKotlin vs Java-A Comparison for Application Development Projects.pdf
Kotlin vs Java-A Comparison for Application Development Projects.pdfTechugo
 
Grokking TechTalk #26: Kotlin, Understand the Magic
Grokking TechTalk #26: Kotlin, Understand the MagicGrokking TechTalk #26: Kotlin, Understand the Magic
Grokking TechTalk #26: Kotlin, Understand the MagicGrokking VN
 
Pragmatic Smalltalk
Pragmatic SmalltalkPragmatic Smalltalk
Pragmatic SmalltalkESUG
 
2011 JavaOne Fun with EJB 3.1 and OpenEJB
2011 JavaOne Fun with EJB 3.1 and OpenEJB2011 JavaOne Fun with EJB 3.1 and OpenEJB
2011 JavaOne Fun with EJB 3.1 and OpenEJBDavid Blevins
 
Plone IDE - the future of Plone development
Plone IDE - the future of Plone developmentPlone IDE - the future of Plone development
Plone IDE - the future of Plone developmentMikko Ohtamaa
 
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...mCloud
 
Kotlin for android development
Kotlin for android developmentKotlin for android development
Kotlin for android developmentJalpesh Vasa
 

Semelhante a Kotlin @ StrangeLoop 2011 (15)

DCI - Data, Context and Interaction @ Jug Lugano May 2011
DCI - Data, Context and Interaction @ Jug Lugano May 2011 DCI - Data, Context and Interaction @ Jug Lugano May 2011
DCI - Data, Context and Interaction @ Jug Lugano May 2011
 
Building Languages for the JVM - StarTechConf 2011
Building Languages for the JVM - StarTechConf 2011Building Languages for the JVM - StarTechConf 2011
Building Languages for the JVM - StarTechConf 2011
 
Kotlin
KotlinKotlin
Kotlin
 
A new world with cdi en
A new world with cdi enA new world with cdi en
A new world with cdi en
 
Kotlin vs Java-A Comparison for Application Development Projects.pdf
Kotlin vs Java-A Comparison for Application Development Projects.pdfKotlin vs Java-A Comparison for Application Development Projects.pdf
Kotlin vs Java-A Comparison for Application Development Projects.pdf
 
Grokking TechTalk #26: Kotlin, Understand the Magic
Grokking TechTalk #26: Kotlin, Understand the MagicGrokking TechTalk #26: Kotlin, Understand the Magic
Grokking TechTalk #26: Kotlin, Understand the Magic
 
Pragmatic Smalltalk
Pragmatic SmalltalkPragmatic Smalltalk
Pragmatic Smalltalk
 
Capitol js
Capitol jsCapitol js
Capitol js
 
Webops dashboards
Webops dashboardsWebops dashboards
Webops dashboards
 
2011 JavaOne Fun with EJB 3.1 and OpenEJB
2011 JavaOne Fun with EJB 3.1 and OpenEJB2011 JavaOne Fun with EJB 3.1 and OpenEJB
2011 JavaOne Fun with EJB 3.1 and OpenEJB
 
Plone IDE - the future of Plone development
Plone IDE - the future of Plone developmentPlone IDE - the future of Plone development
Plone IDE - the future of Plone development
 
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
Developers’ mDay u Banjoj Luci - Duško Bajić, Kotlin User Group Bosnia – Kotl...
 
Slides kotlin yajug
Slides kotlin yajugSlides kotlin yajug
Slides kotlin yajug
 
Kotlin for android development
Kotlin for android developmentKotlin for android development
Kotlin for android development
 
Intro to Kotlin
Intro to KotlinIntro to Kotlin
Intro to Kotlin
 

Último

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
🐬 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 Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
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
 
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
 
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
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 
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
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 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 Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
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
 
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
 
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
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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...
 
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
 

Kotlin @ StrangeLoop 2011

  • 1. The Kotlin Programming Language Andrey Breslav Monday, September 19, 2011
  • 2. What is Kotlin? 2 Monday, September 19, 2011
  • 3. What is Kotlin? • Statically typed 2 Monday, September 19, 2011
  • 4. What is Kotlin? • Statically typed • object-oriented 2 Monday, September 19, 2011
  • 5. What is Kotlin? • Statically typed • object-oriented • JVM-targeted 2 Monday, September 19, 2011
  • 6. What is Kotlin? • Statically typed • object-oriented • JVM-targeted • general-purpose 2 Monday, September 19, 2011
  • 7. What is Kotlin? • Statically typed • object-oriented • JVM-targeted • general-purpose • programming language 2 Monday, September 19, 2011
  • 8. What is Kotlin? • Statically typed • object-oriented • JVM-targeted • general-purpose • programming language • developed by JetBrains 2 Monday, September 19, 2011
  • 9. What is Kotlin? • Statically typed • object-oriented • JVM-targeted • general-purpose • programming language • developed by JetBrains ➡ intended for industrial use 2 Monday, September 19, 2011
  • 10. What is Kotlin? • Statically typed • object-oriented • JVM-targeted • general-purpose • programming language • developed by JetBrains ➡ intended for industrial use • Docs available today 2 Monday, September 19, 2011
  • 11. What is Kotlin? • Statically typed • object-oriented • JVM-targeted • general-purpose • programming language • developed by JetBrains ➡ intended for industrial use • Docs available today • Public beta is planned for the end of 2011 2 Monday, September 19, 2011
  • 12. Goal-wise... 3 Monday, September 19, 2011
  • 13. Goal-wise... • Number of research papers we are planning to publish on Kotlin is 3 Monday, September 19, 2011
  • 14. Goal-wise... • Number of research papers we are planning to publish on Kotlin is ➡ Zero 3 Monday, September 19, 2011
  • 15. Goal-wise... • Number of research papers we are planning to publish on Kotlin is ➡ Zero ➡ ... or really close to that 3 Monday, September 19, 2011
  • 16. Outline • Motivation • Feature overview • Basic syntax • Classes and Types • Higher-order functions • Type-safe Groovy-style Builders 4 Monday, September 19, 2011
  • 17. Motivation 5 Monday, September 19, 2011
  • 18. Motivation • Why a new language? 5 Monday, September 19, 2011
  • 19. Motivation • Why a new language? ➡ We are not satisfied with the existing ones ➡ And we have had a close look at many of them over 10 years 5 Monday, September 19, 2011
  • 20. Motivation • Why a new language? ➡ We are not satisfied with the existing ones ➡ And we have had a close look at many of them over 10 years • Design goals 5 Monday, September 19, 2011
  • 21. Motivation • Why a new language? ➡ We are not satisfied with the existing ones ➡ And we have had a close look at many of them over 10 years • Design goals ➡ Full Java interoperability 5 Monday, September 19, 2011
  • 22. Motivation • Why a new language? ➡ We are not satisfied with the existing ones ➡ And we have had a close look at many of them over 10 years • Design goals ➡ Full Java interoperability ➡ Compiles as fast as Java 5 Monday, September 19, 2011
  • 23. Motivation • Why a new language? ➡ We are not satisfied with the existing ones ➡ And we have had a close look at many of them over 10 years • Design goals ➡ Full Java interoperability ➡ Compiles as fast as Java ➡ Safer than Java 5 Monday, September 19, 2011
  • 24. Motivation • Why a new language? ➡ We are not satisfied with the existing ones ➡ And we have had a close look at many of them over 10 years • Design goals ➡ Full Java interoperability ➡ Compiles as fast as Java ➡ Safer than Java ➡ More concise than Java 5 Monday, September 19, 2011
  • 25. Motivation • Why a new language? ➡ We are not satisfied with the existing ones ➡ And we have had a close look at many of them over 10 years • Design goals ➡ Full Java interoperability ➡ Compiles as fast as Java ➡ Safer than Java ➡ More concise than Java ➡ Way simpler than Scala 5 Monday, September 19, 2011
  • 26. Feature overview 6 Monday, September 19, 2011
  • 27. Feature overview • Language features 6 Monday, September 19, 2011
  • 28. Feature overview • Language features ➡ Static null-safety guarantees 6 Monday, September 19, 2011
  • 29. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") 6 Monday, September 19, 2011
  • 30. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation 6 Monday, September 19, 2011
  • 31. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) 6 Monday, September 19, 2011
  • 32. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) ➡ Reified generics 6 Monday, September 19, 2011
  • 33. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) ➡ Reified generics ➡ Declaration-site variance & "Type projections" 6 Monday, September 19, 2011
  • 34. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) ➡ Reified generics ➡ Declaration-site variance & "Type projections" ➡ Extension functions 6 Monday, September 19, 2011
  • 35. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) ➡ Reified generics ➡ Declaration-site variance & "Type projections" ➡ Extension functions ➡ Modules and Build infrastructure 6 Monday, September 19, 2011
  • 36. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) ➡ Reified generics ➡ Declaration-site variance & "Type projections" ➡ Extension functions ➡ Modules and Build infrastructure ➡ Inline-functions (zero-overhead closures) 6 Monday, September 19, 2011
  • 37. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) ➡ Reified generics ➡ Declaration-site variance & "Type projections" ➡ Extension functions ➡ Modules and Build infrastructure ➡ Inline-functions (zero-overhead closures) ➡ Pattern matching 6 Monday, September 19, 2011
  • 38. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) ➡ Reified generics ➡ Declaration-site variance & "Type projections" ➡ Extension functions ➡ Modules and Build infrastructure ➡ Inline-functions (zero-overhead closures) ➡ Pattern matching ➡ ... 6 Monday, September 19, 2011
  • 39. Feature overview • Language features ➡ Static null-safety guarantees ➡ Higher-order functions ("closures") ➡ Traits & First-class delegation ➡ Properties (no fields) ➡ Reified generics ➡ Declaration-site variance & "Type projections" ➡ Extension functions ➡ Modules and Build infrastructure ➡ Inline-functions (zero-overhead closures) ➡ Pattern matching ➡ ... • Full-featured IDE by JetBrains from the very beginning 6 Monday, September 19, 2011
  • 40. Code examples • Functions • Java interoperability • String templates • Local variables • Type inference • Extension functions and properties • Null-safety 7 Monday, September 19, 2011
  • 41. Hello, world! namespace hello fun main(args : Array<String>) : Unit { println("Hello, world!") } fun println(message : String) { System.out?.println(message) } 8 Monday, September 19, 2011
  • 42. Hello, <names>! fun main(args : Array<String>) { var names : String = "" for (i in args.indices) { names += args[i] if (i + 1 < args.size) names += ", " } println("Hello, $names!") } val Array<*>.indices : Iterable<Int> get() = IntRange<Int>(0, size - 1) 9 Monday, September 19, 2011
  • 43. Hello, <names>! (Faster version) fun main(args : Array<String>) { val names = StringBuilder() for (i in args.indices) { names += args[i] if (i + 1 < args.size) names += ", " } println("Hello, $names!") } fun StringBuilder.plusAssign(s : String) { this.append(s) } 10 Monday, September 19, 2011
  • 44. Hello, <names>! (Realistic version) fun main(args : Array<String>) { println("Hello, ${args.join(", ")}!") } fun <T> Iterable<T>.join(separator : String) : String { val names = StringBuilder() forit (this) { names += it.next() if (it.hasNext()) names += separator } return names.toString() } 11 Monday, September 19, 2011
  • 45. join() and forit() fun <T> Iterable<T>.join(separator : String) : String { val names = StringBuilder() forit (this) { names += it.next() if (it.hasNext()) names += separator } return names.toString() } fun <T> forit(col : Iterable<T>, f : fun(Iterator<T>) : Unit) { val it = col.iterator() while (it.hasNext()) { f(it) } } 12 Monday, September 19, 2011
  • 46. Null-safety fun parseInt(s : String) : Int? { try { return Integer.parseInt(s) } catch (e : NumberFormatException) { return null } } fun main(args : Array<String>) { val x = parseInt("123") val y = parseInt("Hello") print(x?.times(2)) // Can't say: print(x * 2) if (x != null) { print(x * 2) } } 13 Monday, September 19, 2011
  • 47. Types Syntax Class types List<Foo> Nullable types Foo? Function types fun (Int) : String Tuple types (Double, Double) Self type This Special types Top Any? Bottom Nothing No meaningful return value Unit 14 Monday, September 19, 2011
  • 48. Mapping to Java types Kotlin GEN Java LOAD Kotlin Any Object Any? Unit void Unit Int int Int Int? Integer Int? String String String? Array<Foo> Foo[] Array<Foo?>? Array<Int> int[] Array<Int>? Nothing - - Foo Foo Foo? 15 Monday, September 19, 2011
  • 49. Automatic casts and When fun foo(obj : Any?) { if (obj is String) { obj.get(0) } when (obj) { is String => obj.get(0) is Int => obj.plus(1) !is Boolean => null } } 16 Monday, September 19, 2011
  • 50. More on when-expressions fun bar(x : Int) { when (x) { 0 => "Zero" 1, 2, 3 => "1, 2 or 3" x + 1 => "Really strange" in 10..100 => "In range" !in 100..1000 => "Out of range" } } 17 Monday, September 19, 2011
  • 51. Classes open class Parent(p : Bar) { open fun foo() {} fun bar() {} } class Child(p : Bar) : Parent(p) { override fun foo() {} } • Any is the default supertype • Constructors must initialize supertypes • Final by default, explicit override annotations 18 Monday, September 19, 2011
  • 52. Traits trait T1 : Class1, OtherTrait { // No state } class Foo(p : Bar) : Class1(p), T1, T2 { ... } class Decorator(p : T2) : Class2, T2 by p { ... } 19 Monday, September 19, 2011
  • 53. Disambiguation trait A { fun foo() : Int = 1 // open by default } open class B() { open fun foo() : Int = 2 } class C() : B(), A { override fun foo() = super<A>.foo() } 20 Monday, September 19, 2011
  • 54. First-class functions • Functions ➡ fun f(p : Int) : String • Function types ➡ fun (p : Int) : String ➡ fun (Int) : String • Function literals ➡ {p => p.toString()} ➡ {(p : Int) => p.toString()} ➡ {(p : Int) : String => p.toString()} 21 Monday, September 19, 2011
  • 55. Higher-order functions fun <T> filter( c : Iterable<T>, f : fun(T) : Boolean) : Iterable<T> • filter(list, {s => s.length < 3}) ➡ Sugar: last function literal argument ✦ filter(list) {s => s.length < 3} ➡ Sugar: one-parameter function literal ✦ filter(list) { it.length < 3 } 22 Monday, September 19, 2011
  • 56. Infix function calls: "LINQ" a.contains(b) // is the same as a contains b users filter { it hasPrivilege WRITE } map { it => it.fullName } orderBy { lastName } 23 Monday, September 19, 2011
  • 57. Lock example (I) myLock.lock() try { // Do something } finally { myLock.unlock() } 24 Monday, September 19, 2011
  • 58. Lock example (II) lock(myLock) { // Do something } fun lock(l : Lock, body : fun () : Unit) 25 Monday, September 19, 2011
  • 59. Lock example (III) inline fun lock(l : Lock, body : fun () : Unit) { myLock.lock() try { body() } finally { myLock.unlock() } } 26 Monday, September 19, 2011
  • 60. Extension functions • Functions ➡ fun Foo.f(p : Int) : String • Function types ➡ fun Foo.(p : Int) : String ➡ fun Foo.(Int) : String • Function literals ➡ {Foo.(p : Int) => this.toString()} ➡ {Foo.(p : Int) : String => this.toString()} 27 Monday, September 19, 2011
  • 61. Builders in Groovy html { head { title "XML encoding with Groovy" } body { h1 "XML encoding with Groovy" p "this format can be used as an alternative markup to XML" /* an element with attributes and text content */ ahref:'http://groovy.codehaus.org' ["Groovy"] } } 28 Monday, September 19, 2011
  • 62. Builders in Kotlin html { head { title { +"XML encoding with Kotlin" } } body { h1 { +"XML encoding with Kotlin" } p { +"this format is now type-safe" } /* an element with attributes and text content */ a(href="http://jetbrains.com/kotlin") { +"Kotlin" } } } 29 Monday, September 19, 2011
  • 63. Builders: Implementation (I) • Function definition fun html(init : fun HTML.() : Unit) : HTML { val html = HTML() html.init() return html } • Usage html { this.head { ... } } 30 Monday, September 19, 2011
  • 64. Builders: Implementation (II) • Function definition fun html(init : fun HTML.() : Unit) : HTML { val html = HTML() html.init() return html } • Usage html { head { ... } } 31 Monday, September 19, 2011
  • 65. Builders: Implementation (III) abstract class Tag(val name : String) : Element { val children = ArrayList<Element>() val attributes = HashMap<String, String>() } abstract class TagWithText(name : String) : Tag(name) { fun String.plus() { children.add(TextElement(this)) } } class HTML() : TagWithText("html") { fun head(init : fun Head.() : Unit) { } fun body(init : fun Body.() : Unit) { } } 32 Monday, September 19, 2011
  • 66. Builders in Kotlin html { head { title { +"XML encoding with Kotlin" } } body { h1 { +"XML encoding with Kotlin" } p { +"this format is now type-safe" } /* an element with attributes and text content */ a(href="http://jetbrains.com/kotlin") { +"Kotlin" } } } 33 Monday, September 19, 2011
  • 67. Generics: Invariance class List<T> { fun add(t : T) fun get(index : Int) : T } val ints = List<Int>() val anys : List<Any> = ints anys.add("1") // Cause of the problem val i : Int = ints.get(0) // !!! 34 Monday, September 19, 2011
  • 68. Generics: Invariance class List<T> { fun add(t : T) fun get(index : Int) : T } val ints = List<Int>() val anys : List<Any> = ints anys.add("1") // Cause of the problem val i : Int = ints.get(0) // !!! 34 Monday, September 19, 2011
  • 69. Generics: Declaration-site variance class List<T> { List<Int> >:< List<Any> fun add(t : T) val ints = List<Int>() fun get() : T val anys : List<Any> = ints } class Producer<out T> { val ints = Producer<Int>() fun get() : T val anys : Producer<Any> = ints } class Consumer<in T> { val anys = Consumer<Any>() fun add(t : T) val ints : Consumer<Int> = anys } 35 Monday, September 19, 2011
  • 70. Generics: Declaration-site variance class List<T> { List<Int> >:< List<Any> fun add(t : T) val ints = List<Int>() fun get() : T val anys : List<Any> = ints } class Producer<out T> { val ints = Producer<Int>() fun get() : T val anys : Producer<Any> = ints } class Consumer<in T> { val anys = Consumer<Any>() fun add(t : T) val ints : Consumer<Int> = anys } 35 Monday, September 19, 2011
  • 71. Generics: Declaration-site variance class List<T> { List<Int> >:< List<Any> fun add(t : T) val ints = List<Int>() fun get() : T val anys : List<Any> = ints } class Producer<out T> { val ints = Producer<Int>() fun get() : T val anys : Producer<Any> = ints } class Consumer<in T> { val anys = Consumer<Any>() fun add(t : T) val ints : Consumer<Int> = anys } 35 Monday, September 19, 2011
  • 72. Generics: Use-site variance val ints = List<Int>() val anysOut : List<out Any> = ints anysOut.add("1") // Not available val i : Int = ints.get() // No problem 36 Monday, September 19, 2011
  • 73. Generics: Use-site variance val ints = List<Int>() val anysOut : List<out Any> = ints anysOut.add("1") // Not available val i : Int = ints.get() // No problem val anys = List<Any>() val intsIn : List<in Int> = anys intsIn.add(0) val obj = intsIn.get() // : Any? 36 Monday, September 19, 2011
  • 74. Reified generics • Type information in retained at runtime ➡ foo is List<T> ➡ Array<T>(3) ➡ T.create() • Java types are still erased ➡ foo is java.util.List<*> 37 Monday, September 19, 2011
  • 75. Resources • Documentation: ➡ http://jetbrains.com/kotlin • Blog: ➡ http://blog.jetbrains.com/kotlin • Twitter: ➡ @project_kotlin ➡ @abreslav 38 Monday, September 19, 2011