SlideShare a Scribd company logo
1 of 30
Download to read offline
NO EXCUSES,
SWITCH TO KOTLIN
NO EXCUSES,
SWITCH TO KOTLIN
t
Thijs Suijten
Mobile developer @ Q42
@tsuijten
GETTING EVERYBODY ONBOARD
TEAM Q42 CLIENT
val s1: String = "Hello" // Immutable variable

val s2 = "how are you" // Type is inferred
Variables
var s3 = "John" // Mutable variable

s3 = "Thijs" // Assign a different value
// w00t! String Interpolation

println("$s1, $s2 $s3?")
//> Hello, how are you Thijs?
fun reformat(str: String,
normalize: Boolean = true,
upperCase: Boolean = true): String {

...

}
Functions
reformat("Hello world")

reformat("Hello world", false, false)

reformat("Hello world", upperCase = false)
// Single-Expression functions
fun twiceTheFun(x: Int) = x * 2
class Person(val firstName: String, 

val age: Int, 

val locale: Locale = ENGLISH) {

fun sayHello() = println("Hi $firstName!")

}
Classes
val thijs = Person("Thijs", 34)

thijs.sayHello() // Hi Thijs!
class Cat(name: String) {

val name: String = name

}
val x: String? = getSomeOptionalString()

x.length // Does not compile.
Null safety / optionals
val y: String = null // Does not compile.
if (x != null) {

x.length // Compiles!

}
// Safe call

val optLength = foo?.bar?.length // Returns Int?



// Elvis operator.

val length = optLength ?: -1
Data classes
class User(val name: String, val age: Int)
val thijs = User("Thijs", 35)
println(thijs) // User(name=Thijs, age=35)
val bday = thijs.copy(age = 36) // Named params!

println(bday) // User(name=Thijs, age=36)
data
Data classes
public class User {

private String name;

private int age;



public User(String name, int age) {

this.name = name;

this.age = age;

}



public String getName() {

return name;

}



public void setName(String name) {

this.name = name;

}



public int getAge() {

return age;

}



public void setAge(int age) {

this.age = age;

}



@Override public boolean equals(Object o) {

if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;



User user = (User) o;



if (age != user.age) return false;

return name != null ? name.equals(user.name) : user.name == null;

}



@Override public int hashCode() {

int result = name != null ? name.hashCode() : 0;

result = 31 * result + age;

return result;

}



@Override public String toString() {

return "User{" +

"name='" + name + ''' +

", age=" + age +

'}';

}

}
// Remember this?

data class User(val name: String, val age: Int)
public class User {

private String name;

private int age;



public User(String name, int age) {

this.name = name;

this.age = age;

}



public String getName() {

return name;

}



public void setName(String name) {

this.name = name;

}



public int getAge() {

return age;

}



public void setAge(int age) {

this.age = age;

}



@Override public boolean equals(Object o) {

if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;



User user = (User) o;



if (age != user.age) return false;

return name != null ? name.equals(user.name) : user.name == null;

}



@Override public int hashCode() {

int result = name != null ? name.hashCode() : 0;

result = 31 * result + age;

return result;

}



@Override public String toString() {

return "User{" +

"name='" + name + ''' +

", age=" + age +

'}';

}

}
Functional / lambas
val sum = listOf(1, 2, 3, 4, 5) // 1,2,3,4,5

.filter { number -> number < 5 } // 1,2,3,4

.map { it * 2 } // 2,4,6,8

.sum() // 20
listOf("Zack", "Bob", "Thijs", "Julie", "Rob")

.filter { it.length > 3 } // Zack, Thijs, Julie

.sorted() // Julie, Thijs, Zack
Collections
// Interface List<String>

val fruits = listOf("Apple", "Pear", "Orange")

fruits.add("Strawberry") // Compiler error
// Interface MutableList<String>

val veggies = mutableListOf("Kale", "Spinach", "Lettuce")

veggies.add("Tomato")

veggies += "Cucumber" // Operator overloading
When statement
// Java

if (firstName.equals("Dan")) {

person.setTeam(programmers);

} else if (lastName.equals("Jamie")) {

person.setTeam(designers);

} else {

person.setTeam(others);

}
// Kotlin

when {

firstName == “Dan" -> person.team = programmers

lastName == "Jamie" -> person.team = designers

else -> person.team = others

}
When statement
// Java

switch (firstName) {

case "Dan":

case "Jay":

person.setTeam(programmers);

break;

case "Jamie":

person.setTeam(designers);

break;

default:

person.setTeam(others);

}
// Kotlin

when (firstName) {

"Dan", "Jay" -> person.team = programmers

"Jamie" -> person.team = designers

else -> person.team = others

}
When statement
when (x) {

1 -> print("x = 1")

is Int -> print(x + 1)

is String -> print(x.length + 1)

is IntArray -> print(x.sum())

in 10..20 -> print("Between 10 and 20")

}
val outcome = when(x) {

1 -> "x = 1"

"Hello" -> "is it me you're looking for?"

in 10..20 -> "Between 10 and 20"

}
Extensions
// Java

StringUtils.capitalize(AddressUtils.extractStreet(address))
// Kotlin

address.street.capitalize()
// Extension function

fun String.capitalize() = StringUtils.capitalize(this)



// Extension property

val String.street: String get() = AddressUtils.extractStreet(this)
Kotlin Android extensions
<TextView android:id="@+id/greeting"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>



<Button android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Click me!"/>
override fun onCreate(savedInstanceState: Bundle?) {

//…


greeting.text = "Hello"

button.onClick { toast("Button clicked!") }

}
Interop Demo
Who is using Kotlin
NO EXCUSES,
SWITCH TO KOTLIN
..
thijs@q42.nl / @tsuijten
try.kotlinlang.org

More Related Content

What's hot

Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...Ramires Moreira
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with YieldJason Myers
 
Kotlin killed Java stars
Kotlin killed Java starsKotlin killed Java stars
Kotlin killed Java starsMatteo Bonifazi
 
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Bongwon Lee
 
8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会Yusuke Ando
 
(안드로이드 개발자를 위한) 오픈소스 라이브러리 사용 가이드
(안드로이드 개발자를 위한) 오픈소스 라이브러리 사용 가이드(안드로이드 개발자를 위한) 오픈소스 라이브러리 사용 가이드
(안드로이드 개발자를 위한) 오픈소스 라이브러리 사용 가이드Taeho Kim
 
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
1st CI&T Lightning Talks: Writing better code with Object Calisthenics1st CI&T Lightning Talks: Writing better code with Object Calisthenics
1st CI&T Lightning Talks: Writing better code with Object CalisthenicsLucas Arruda
 
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS AppsBeyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS AppsRebecca Murphey
 
Functionality Focused Code Organization
Functionality Focused Code OrganizationFunctionality Focused Code Organization
Functionality Focused Code OrganizationRebecca Murphey
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsGuilherme Blanco
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Vagmi Mudumbai
 
jQuery Namespace Pattern
jQuery Namespace PatternjQuery Namespace Pattern
jQuery Namespace PatternDiego Fleury
 
A practical introduction to Kotlin
A practical introduction to KotlinA practical introduction to Kotlin
A practical introduction to KotlinStathis Souris
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Gesh Markov
 

What's hot (20)

Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
Torne seu código legível com enums | Cocoa heads 2018 fortaleza - Ramires Mor...
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with Yield
 
Kotlin killed Java stars
Kotlin killed Java starsKotlin killed Java stars
Kotlin killed Java stars
 
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
 
8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会
 
(안드로이드 개발자를 위한) 오픈소스 라이브러리 사용 가이드
(안드로이드 개발자를 위한) 오픈소스 라이브러리 사용 가이드(안드로이드 개발자를 위한) 오픈소스 라이브러리 사용 가이드
(안드로이드 개발자를 위한) 오픈소스 라이브러리 사용 가이드
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
 
Emo
EmoEmo
Emo
 
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
1st CI&T Lightning Talks: Writing better code with Object Calisthenics1st CI&T Lightning Talks: Writing better code with Object Calisthenics
1st CI&T Lightning Talks: Writing better code with Object Calisthenics
 
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS AppsBeyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS Apps
 
Functionality Focused Code Organization
Functionality Focused Code OrganizationFunctionality Focused Code Organization
Functionality Focused Code Organization
 
BVJS
BVJSBVJS
BVJS
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
 
Jquery Fundamentals
Jquery FundamentalsJquery Fundamentals
Jquery Fundamentals
 
jQuery Namespace Pattern
jQuery Namespace PatternjQuery Namespace Pattern
jQuery Namespace Pattern
 
A practical introduction to Kotlin
A practical introduction to KotlinA practical introduction to Kotlin
A practical introduction to Kotlin
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)
 
Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 
Ecmascript 6
Ecmascript 6Ecmascript 6
Ecmascript 6
 

Viewers also liked

Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Arnaud Giuliani
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlinThijs Suijten
 
Spring 5 + Kotlin (Rus)
Spring 5 + Kotlin (Rus)Spring 5 + Kotlin (Rus)
Spring 5 + Kotlin (Rus)Siarhei Krukau
 
Banking case presentation final
Banking case presentation finalBanking case presentation final
Banking case presentation finalKritika Gupta
 
Excuse managementformanagers
Excuse managementformanagersExcuse managementformanagers
Excuse managementformanagerscem lale
 
The 7 most popular excuses why not to build a startup
The 7 most popular excuses why not to build a startupThe 7 most popular excuses why not to build a startup
The 7 most popular excuses why not to build a startupKarol Zielinski
 
Ona 2013 data journalism no excuses with la nacion data
Ona 2013 data journalism no excuses with la nacion dataOna 2013 data journalism no excuses with la nacion data
Ona 2013 data journalism no excuses with la nacion datalndata
 
15 Excuses unproductive people basically always use.
15 Excuses unproductive people basically always use.15 Excuses unproductive people basically always use.
15 Excuses unproductive people basically always use.MetaKave
 
15 terrible excuses for not starting your own business
15 terrible excuses for not starting your own business15 terrible excuses for not starting your own business
15 terrible excuses for not starting your own businessSonu Pandey
 
New Austrian Tunnelling Method (NATM) Annex
New Austrian Tunnelling Method (NATM) AnnexNew Austrian Tunnelling Method (NATM) Annex
New Austrian Tunnelling Method (NATM) AnnexAustrian Standards
 
Excuses, Excuses, Excuse Personas
Excuses, Excuses, Excuse PersonasExcuses, Excuses, Excuse Personas
Excuses, Excuses, Excuse PersonasMotivate Design
 
Business Hacks to Make Creating an Operations Plan Simple
Business Hacks to Make Creating an Operations Plan SimpleBusiness Hacks to Make Creating an Operations Plan Simple
Business Hacks to Make Creating an Operations Plan SimpleJim Muehlhausen
 
7 Excuses Business Owners Don't Have an Operations Plan
7 Excuses Business Owners Don't Have an Operations Plan7 Excuses Business Owners Don't Have an Operations Plan
7 Excuses Business Owners Don't Have an Operations PlanJim Muehlhausen
 
How To Be A Better Boss in 2015
How To Be A Better Boss in 2015How To Be A Better Boss in 2015
How To Be A Better Boss in 2015When I Work
 
The Ultimate Excuse Generator - Excuses For When You're Late To Work
The Ultimate Excuse Generator - Excuses For When You're Late To WorkThe Ultimate Excuse Generator - Excuses For When You're Late To Work
The Ultimate Excuse Generator - Excuses For When You're Late To WorkWhen I Work
 
A No-Excuses Guide to Blogging
A No-Excuses Guide to BloggingA No-Excuses Guide to Blogging
A No-Excuses Guide to BloggingSacha Chua
 
7 steps to get beyond excuses
7 steps to get beyond excuses7 steps to get beyond excuses
7 steps to get beyond excusesHarish
 
13 Personality Traits Of A Horrible Employee
13 Personality Traits Of A Horrible Employee13 Personality Traits Of A Horrible Employee
13 Personality Traits Of A Horrible EmployeeD B
 

Viewers also liked (20)

Kotlin
KotlinKotlin
Kotlin
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlin
 
Spring 5 + Kotlin (Rus)
Spring 5 + Kotlin (Rus)Spring 5 + Kotlin (Rus)
Spring 5 + Kotlin (Rus)
 
Banking case presentation final
Banking case presentation finalBanking case presentation final
Banking case presentation final
 
Excuse managementformanagers
Excuse managementformanagersExcuse managementformanagers
Excuse managementformanagers
 
The 7 most popular excuses why not to build a startup
The 7 most popular excuses why not to build a startupThe 7 most popular excuses why not to build a startup
The 7 most popular excuses why not to build a startup
 
Ona 2013 data journalism no excuses with la nacion data
Ona 2013 data journalism no excuses with la nacion dataOna 2013 data journalism no excuses with la nacion data
Ona 2013 data journalism no excuses with la nacion data
 
15 Excuses unproductive people basically always use.
15 Excuses unproductive people basically always use.15 Excuses unproductive people basically always use.
15 Excuses unproductive people basically always use.
 
15 terrible excuses for not starting your own business
15 terrible excuses for not starting your own business15 terrible excuses for not starting your own business
15 terrible excuses for not starting your own business
 
New Austrian Tunnelling Method (NATM) Annex
New Austrian Tunnelling Method (NATM) AnnexNew Austrian Tunnelling Method (NATM) Annex
New Austrian Tunnelling Method (NATM) Annex
 
Excuses, Excuses, Excuse Personas
Excuses, Excuses, Excuse PersonasExcuses, Excuses, Excuse Personas
Excuses, Excuses, Excuse Personas
 
Business Hacks to Make Creating an Operations Plan Simple
Business Hacks to Make Creating an Operations Plan SimpleBusiness Hacks to Make Creating an Operations Plan Simple
Business Hacks to Make Creating an Operations Plan Simple
 
7 Excuses Business Owners Don't Have an Operations Plan
7 Excuses Business Owners Don't Have an Operations Plan7 Excuses Business Owners Don't Have an Operations Plan
7 Excuses Business Owners Don't Have an Operations Plan
 
Coursera Cassandra Driver
Coursera Cassandra DriverCoursera Cassandra Driver
Coursera Cassandra Driver
 
How To Be A Better Boss in 2015
How To Be A Better Boss in 2015How To Be A Better Boss in 2015
How To Be A Better Boss in 2015
 
The Ultimate Excuse Generator - Excuses For When You're Late To Work
The Ultimate Excuse Generator - Excuses For When You're Late To WorkThe Ultimate Excuse Generator - Excuses For When You're Late To Work
The Ultimate Excuse Generator - Excuses For When You're Late To Work
 
A No-Excuses Guide to Blogging
A No-Excuses Guide to BloggingA No-Excuses Guide to Blogging
A No-Excuses Guide to Blogging
 
7 steps to get beyond excuses
7 steps to get beyond excuses7 steps to get beyond excuses
7 steps to get beyond excuses
 
13 Personality Traits Of A Horrible Employee
13 Personality Traits Of A Horrible Employee13 Personality Traits Of A Horrible Employee
13 Personality Traits Of A Horrible Employee
 

Similar to No excuses, switch to kotlin

Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018 Codemotion
 
First few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesFirst few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesNebojša Vukšić
 
About java
About javaAbout java
About javaJay Xu
 
かとうの Kotlin 講座 こってり版
かとうの Kotlin 講座 こってり版かとうの Kotlin 講座 こってり版
かとうの Kotlin 講座 こってり版Yutaka Kato
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Tomasz Dziuda
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timekarianneberg
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfarjuncp10
 
Kotlin for Android Developers
Kotlin for Android DevelopersKotlin for Android Developers
Kotlin for Android DevelopersHassan Abid
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Lukas Ruebbelke
 
Features of Kotlin I find exciting
Features of Kotlin I find excitingFeatures of Kotlin I find exciting
Features of Kotlin I find excitingRobert MacLean
 

Similar to No excuses, switch to kotlin (20)

Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
 
First few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesFirst few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examples
 
About java
About javaAbout java
About java
 
Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
 
かとうの Kotlin 講座 こってり版
かとうの Kotlin 講座 こってり版かとうの Kotlin 講座 こってり版
かとうの Kotlin 講座 こってり版
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en time
 
Miracle of std lib
Miracle of std libMiracle of std lib
Miracle of std lib
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
 
Kotlin for Android Developers
Kotlin for Android DevelopersKotlin for Android Developers
Kotlin for Android Developers
 
Pure kotlin
Pure kotlinPure kotlin
Pure kotlin
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Swift Study #7
Swift Study #7Swift Study #7
Swift Study #7
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Kotlin
KotlinKotlin
Kotlin
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015Impress Your Friends with EcmaScript 2015
Impress Your Friends with EcmaScript 2015
 
Features of Kotlin I find exciting
Features of Kotlin I find excitingFeatures of Kotlin I find exciting
Features of Kotlin I find exciting
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 

No excuses, switch to kotlin

  • 2. NO EXCUSES, SWITCH TO KOTLIN t Thijs Suijten Mobile developer @ Q42 @tsuijten
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 10.
  • 11.
  • 12. val s1: String = "Hello" // Immutable variable
 val s2 = "how are you" // Type is inferred Variables var s3 = "John" // Mutable variable
 s3 = "Thijs" // Assign a different value // w00t! String Interpolation
 println("$s1, $s2 $s3?") //> Hello, how are you Thijs?
  • 13. fun reformat(str: String, normalize: Boolean = true, upperCase: Boolean = true): String {
 ...
 } Functions reformat("Hello world")
 reformat("Hello world", false, false)
 reformat("Hello world", upperCase = false) // Single-Expression functions fun twiceTheFun(x: Int) = x * 2
  • 14. class Person(val firstName: String, 
 val age: Int, 
 val locale: Locale = ENGLISH) {
 fun sayHello() = println("Hi $firstName!")
 } Classes val thijs = Person("Thijs", 34)
 thijs.sayHello() // Hi Thijs! class Cat(name: String) {
 val name: String = name
 }
  • 15. val x: String? = getSomeOptionalString()
 x.length // Does not compile. Null safety / optionals val y: String = null // Does not compile. if (x != null) {
 x.length // Compiles!
 } // Safe call
 val optLength = foo?.bar?.length // Returns Int?
 
 // Elvis operator.
 val length = optLength ?: -1
  • 16. Data classes class User(val name: String, val age: Int) val thijs = User("Thijs", 35) println(thijs) // User(name=Thijs, age=35) val bday = thijs.copy(age = 36) // Named params!
 println(bday) // User(name=Thijs, age=36) data
  • 17. Data classes public class User {
 private String name;
 private int age;
 
 public User(String name, int age) {
 this.name = name;
 this.age = age;
 }
 
 public String getName() {
 return name;
 }
 
 public void setName(String name) {
 this.name = name;
 }
 
 public int getAge() {
 return age;
 }
 
 public void setAge(int age) {
 this.age = age;
 }
 
 @Override public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null || getClass() != o.getClass()) return false;
 
 User user = (User) o;
 
 if (age != user.age) return false;
 return name != null ? name.equals(user.name) : user.name == null;
 }
 
 @Override public int hashCode() {
 int result = name != null ? name.hashCode() : 0;
 result = 31 * result + age;
 return result;
 }
 
 @Override public String toString() {
 return "User{" +
 "name='" + name + ''' +
 ", age=" + age +
 '}';
 }
 } // Remember this?
 data class User(val name: String, val age: Int) public class User {
 private String name;
 private int age;
 
 public User(String name, int age) {
 this.name = name;
 this.age = age;
 }
 
 public String getName() {
 return name;
 }
 
 public void setName(String name) {
 this.name = name;
 }
 
 public int getAge() {
 return age;
 }
 
 public void setAge(int age) {
 this.age = age;
 }
 
 @Override public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null || getClass() != o.getClass()) return false;
 
 User user = (User) o;
 
 if (age != user.age) return false;
 return name != null ? name.equals(user.name) : user.name == null;
 }
 
 @Override public int hashCode() {
 int result = name != null ? name.hashCode() : 0;
 result = 31 * result + age;
 return result;
 }
 
 @Override public String toString() {
 return "User{" +
 "name='" + name + ''' +
 ", age=" + age +
 '}';
 }
 }
  • 18. Functional / lambas val sum = listOf(1, 2, 3, 4, 5) // 1,2,3,4,5
 .filter { number -> number < 5 } // 1,2,3,4
 .map { it * 2 } // 2,4,6,8
 .sum() // 20 listOf("Zack", "Bob", "Thijs", "Julie", "Rob")
 .filter { it.length > 3 } // Zack, Thijs, Julie
 .sorted() // Julie, Thijs, Zack
  • 19. Collections // Interface List<String>
 val fruits = listOf("Apple", "Pear", "Orange")
 fruits.add("Strawberry") // Compiler error // Interface MutableList<String>
 val veggies = mutableListOf("Kale", "Spinach", "Lettuce")
 veggies.add("Tomato")
 veggies += "Cucumber" // Operator overloading
  • 20. When statement // Java
 if (firstName.equals("Dan")) {
 person.setTeam(programmers);
 } else if (lastName.equals("Jamie")) {
 person.setTeam(designers);
 } else {
 person.setTeam(others);
 } // Kotlin
 when {
 firstName == “Dan" -> person.team = programmers
 lastName == "Jamie" -> person.team = designers
 else -> person.team = others
 }
  • 21. When statement // Java
 switch (firstName) {
 case "Dan":
 case "Jay":
 person.setTeam(programmers);
 break;
 case "Jamie":
 person.setTeam(designers);
 break;
 default:
 person.setTeam(others);
 } // Kotlin
 when (firstName) {
 "Dan", "Jay" -> person.team = programmers
 "Jamie" -> person.team = designers
 else -> person.team = others
 }
  • 22. When statement when (x) {
 1 -> print("x = 1")
 is Int -> print(x + 1)
 is String -> print(x.length + 1)
 is IntArray -> print(x.sum())
 in 10..20 -> print("Between 10 and 20")
 } val outcome = when(x) {
 1 -> "x = 1"
 "Hello" -> "is it me you're looking for?"
 in 10..20 -> "Between 10 and 20"
 }
  • 23. Extensions // Java
 StringUtils.capitalize(AddressUtils.extractStreet(address)) // Kotlin
 address.street.capitalize() // Extension function
 fun String.capitalize() = StringUtils.capitalize(this)
 
 // Extension property
 val String.street: String get() = AddressUtils.extractStreet(this)
  • 24. Kotlin Android extensions <TextView android:id="@+id/greeting"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"/>
 
 <Button android:id="@+id/button"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Click me!"/> override fun onCreate(savedInstanceState: Bundle?) {
 //… 
 greeting.text = "Hello"
 button.onClick { toast("Button clicked!") }
 }
  • 26. Who is using Kotlin
  • 27.
  • 28.