SlideShare a Scribd company logo
1 of 11
Download to read offline
An introduction to Kotlin
What is Kotlin?
● A statically-typed programming language that runs on the JVM
● Developed by JetBrains
● Unveiled 2011, development started about one year earlier
● First-class support for Android since Google I/O 2017
● Full support from Android Studio 3
Why Kotlin?
● Concise - Reduce the amount of boilerplate code
● Safe - Avoid null pointer errors, use immutable types to improve concurrency
● Interoperable - Consume existing Java code/libraries, write code that can be used
from Java
● Allows gradual migrations from Java to Kotlin
● Build for Java, Android, JavaScript and more…
● Powerful IDE:s
Syntax & Semantics
● Pascal-type declaration style for variable and parameter lists:
val myValue: Int = 10
● Semicolon termination optional, should not be used
● Object-oriented style and procedural programming with functional support
● Type inference support:
val myInt = 10
val myString = “Test”
val myClass = MyClass()
● Distinction between nullable and non-nullable types:
var nullable: Int?
var nonNullable: Int
Syntax & Semantics
● Interaction with nullable objects needs special handling:
?. - safe navigation operator
?: - null coalescing operator
!! - assert if expression is null
● Compile-time error checks for null violations
● Unique default constructors:
class Test(private val firstName: String, private val secondName: String)
● Everything are functions, there’s no void:
fun doStuff() { … } // (Unit)
fun add(x: Int, y: Int, z: Int = 0): Int = x+y+c
Syntax & Semantics
● Properties are simple
● Extension functions (similar to c#), Anko:
fun Context.toast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT)
{Toast.makeText(this, message, duration).show()}
● doAsync(), uiThread - will not execute if activity.isFinishing() is true
● Data classes, simplifies POJO classes:
data class myModel(val name: String, val age: Int)
● Declaration deconstructing:
val o = myModel(“Mikael”, 40)
val (name, age) = o
● Object, Companion objects - easy singleton, “static” properties
● Operator overloading - Fixed number of symbolic operators to overload
Syntax & Semantics
● Lambdas - First class citizens
class GamesAdapter(private val games: List<Game>, private val itemClick: (Game) -> Unit)
…
val adapter = GamesAdapter(viewModel.getGamesForView(), {game -> openDetail(game) })
val adapter = GamesAdapter(viewModel.getGamesForView(), {openDetail(it)})
● Inline functions - Reduce memory footprint, increase performance
● Lazy instantiation:
private val allGames: List<Game> by lazy {
repository.getGames()
}
● Lateinit:
private lateinit var viewModel: LoginViewModel
Syntax & Semantics
● Collections - LINQ style: Aggregate, Filtering, Mapping, Elements, Generations,
Ordering
● Flow control specials: When
when(requestCode) {
RequestSortCode -> {
updateView(data?.getStringExtra(SortingActivity.SortingId).toString())
}
else -> super.onActivityResult(requestCode, resultCode, data)
}
● Generics - similar to c#
● Coroutines - async/await similarity - write async code in sequence, and more
Advantages
● Fully native code in a modern way
● Reduce coding, increase readability
● Stable code (almost) by default. Use of immutable, null checks
● Synthetic imports (avoid findViewById)
● Use existing components (Picasso, Mockito, jUnit…)
● Extremely powerful IDEs ranging from syntax to integration (Google play etc)
● Official language for Android
Disadvantages
● No namespaces
● Java to Kotlin converter not 100% accurate
● Method count will increase in compiled code (backing fields, inline)
Links
● Java version
https://github.com/MikaelStalvik/javagameapp
● Kotlin version
https://github.com/MikaelStalvik/kotlingameapp

More Related Content

What's hot

TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript ModulesNoam Kfir
 
Scala on-android
Scala on-androidScala on-android
Scala on-androidlifecoder
 
Smalltalk, the dynamic language
Smalltalk, the dynamic languageSmalltalk, the dynamic language
Smalltalk, the dynamic languagemohamedsamyali
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Divedavanum
 
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015Andrea Zaza
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalkkim.mens
 
.NET compiler platform codename Roslyn
.NET compiler platform codename Roslyn.NET compiler platform codename Roslyn
.NET compiler platform codename RoslynPiotr Benetkiewicz
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.Brian Hsu
 
iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)David Truxall
 
Ruby - a pure object oriented language
Ruby  - a pure object oriented languageRuby  - a pure object oriented language
Ruby - a pure object oriented languagePetru Cioată
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaDILo Surabaya
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin XPeppers
 

What's hot (20)

TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript Modules
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
Scala on-android
Scala on-androidScala on-android
Scala on-android
 
Smalltalk, the dynamic language
Smalltalk, the dynamic languageSmalltalk, the dynamic language
Smalltalk, the dynamic language
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Dive
 
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalk
 
.NET compiler platform codename Roslyn
.NET compiler platform codename Roslyn.NET compiler platform codename Roslyn
.NET compiler platform codename Roslyn
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.
 
iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Ruby - a pure object oriented language
Ruby  - a pure object oriented languageRuby  - a pure object oriented language
Ruby - a pure object oriented language
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
TypeScript
TypeScriptTypeScript
TypeScript
 

Similar to Lightning talk: Kotlin

Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentJayaprakash R
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 
Robust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time ChecksRobust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time ChecksStoyan Nikolov
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure JavaAnton Keks
 
Productivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioProductivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioAhasan Habib
 
What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)Moaid Hathot
 
Unity3D Plugins Development Guide
Unity3D Plugins Development GuideUnity3D Plugins Development Guide
Unity3D Plugins Development GuideKaiJung Chen
 
GDG Madrid - Dart Event - By Iván Zaera
GDG Madrid - Dart Event - By Iván ZaeraGDG Madrid - Dart Event - By Iván Zaera
GDG Madrid - Dart Event - By Iván ZaeraJc Miñarro
 
Understanding Implicits in Scala
Understanding Implicits in ScalaUnderstanding Implicits in Scala
Understanding Implicits in Scaladatamantra
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyMobileAcademy
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming PatternsVasil Remeniuk
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins Udaya Kumar
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageAzilen Technologies Pvt. Ltd.
 

Similar to Lightning talk: Kotlin (20)

Hello, QML
Hello, QMLHello, QML
Hello, QML
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App development
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Robust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time ChecksRobust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time Checks
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure Java
 
Productivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioProductivity Enhencement with Visual Studio
Productivity Enhencement with Visual Studio
 
What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
 
Unit 1
Unit 1Unit 1
Unit 1
 
Unity3D Plugins Development Guide
Unity3D Plugins Development GuideUnity3D Plugins Development Guide
Unity3D Plugins Development Guide
 
GDG Madrid - Dart Event - By Iván Zaera
GDG Madrid - Dart Event - By Iván ZaeraGDG Madrid - Dart Event - By Iván Zaera
GDG Madrid - Dart Event - By Iván Zaera
 
Understanding Implicits in Scala
Understanding Implicits in ScalaUnderstanding Implicits in Scala
Understanding Implicits in Scala
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
 
E sampark with c#.net
E sampark with c#.netE sampark with c#.net
E sampark with c#.net
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming Patterns
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 

Lightning talk: Kotlin

  • 2. What is Kotlin? ● A statically-typed programming language that runs on the JVM ● Developed by JetBrains ● Unveiled 2011, development started about one year earlier ● First-class support for Android since Google I/O 2017 ● Full support from Android Studio 3
  • 3. Why Kotlin? ● Concise - Reduce the amount of boilerplate code ● Safe - Avoid null pointer errors, use immutable types to improve concurrency ● Interoperable - Consume existing Java code/libraries, write code that can be used from Java ● Allows gradual migrations from Java to Kotlin ● Build for Java, Android, JavaScript and more… ● Powerful IDE:s
  • 4. Syntax & Semantics ● Pascal-type declaration style for variable and parameter lists: val myValue: Int = 10 ● Semicolon termination optional, should not be used ● Object-oriented style and procedural programming with functional support ● Type inference support: val myInt = 10 val myString = “Test” val myClass = MyClass() ● Distinction between nullable and non-nullable types: var nullable: Int? var nonNullable: Int
  • 5. Syntax & Semantics ● Interaction with nullable objects needs special handling: ?. - safe navigation operator ?: - null coalescing operator !! - assert if expression is null ● Compile-time error checks for null violations ● Unique default constructors: class Test(private val firstName: String, private val secondName: String) ● Everything are functions, there’s no void: fun doStuff() { … } // (Unit) fun add(x: Int, y: Int, z: Int = 0): Int = x+y+c
  • 6. Syntax & Semantics ● Properties are simple ● Extension functions (similar to c#), Anko: fun Context.toast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT) {Toast.makeText(this, message, duration).show()} ● doAsync(), uiThread - will not execute if activity.isFinishing() is true ● Data classes, simplifies POJO classes: data class myModel(val name: String, val age: Int) ● Declaration deconstructing: val o = myModel(“Mikael”, 40) val (name, age) = o ● Object, Companion objects - easy singleton, “static” properties ● Operator overloading - Fixed number of symbolic operators to overload
  • 7. Syntax & Semantics ● Lambdas - First class citizens class GamesAdapter(private val games: List<Game>, private val itemClick: (Game) -> Unit) … val adapter = GamesAdapter(viewModel.getGamesForView(), {game -> openDetail(game) }) val adapter = GamesAdapter(viewModel.getGamesForView(), {openDetail(it)}) ● Inline functions - Reduce memory footprint, increase performance ● Lazy instantiation: private val allGames: List<Game> by lazy { repository.getGames() } ● Lateinit: private lateinit var viewModel: LoginViewModel
  • 8. Syntax & Semantics ● Collections - LINQ style: Aggregate, Filtering, Mapping, Elements, Generations, Ordering ● Flow control specials: When when(requestCode) { RequestSortCode -> { updateView(data?.getStringExtra(SortingActivity.SortingId).toString()) } else -> super.onActivityResult(requestCode, resultCode, data) } ● Generics - similar to c# ● Coroutines - async/await similarity - write async code in sequence, and more
  • 9. Advantages ● Fully native code in a modern way ● Reduce coding, increase readability ● Stable code (almost) by default. Use of immutable, null checks ● Synthetic imports (avoid findViewById) ● Use existing components (Picasso, Mockito, jUnit…) ● Extremely powerful IDEs ranging from syntax to integration (Google play etc) ● Official language for Android
  • 10. Disadvantages ● No namespaces ● Java to Kotlin converter not 100% accurate ● Method count will increase in compiled code (backing fields, inline)
  • 11. Links ● Java version https://github.com/MikaelStalvik/javagameapp ● Kotlin version https://github.com/MikaelStalvik/kotlingameapp