SlideShare a Scribd company logo
K O T L I N
ANDROID
Kotlin for Android dev
100 % interoperable
with Java
Kotlin for Android devs
Developed by JetBrains
KOTLIN
KOTLIN
2010 - Work Started
2011 - Announced
2016 - 1.0 release
2017 - 1.1 release
Official Android First Class Language
Agenda
What is Kotlin ?
Kotlin for Android devs
Why Kotlin ?
Syntax crash course
Features of Kotlin
QnA
Hands-on Session
https://www.tiobe.com/tiobe-index/
Kotlin is climbing up the ladder
Kotlin for Android devs
• Null references are controlled by the type
system.
• No raw types
• Arrays in Kotlin are invariant
• Kotlin has proper function types, as
opposed to Java’s SAM-conversions
• Use-site variance without wildcards
• Kotlin does not have checked exceptions
Kotlin fixes a series of
issues that Java suffers
from
Checked exceptions
Primitive types that are not classes
Static members
Non-private fields
Wildcard-types
What Java has that Kotlin
does not
KOTLIN & ANDROID
Kotlin can be updated
independently from the OS.
OOP language
with functional
aspects
Modern and
powerful
language
Focuses on
safe concise
and readable
code
Its a statically-typed programming language
What is Kotlin ?
First class tool support
Statically typed programming
language for the JVM,
Android and the browser
What is Kotlin ?
Its a statically-typed programming language
Statically type
What we get by using Java 6/7 + Android -
• Inability to add methods in platform APIs ,
have to use Utils
• NO Lambdas , NO Streams
• NPE - so many of them
What we need
We need modern and smart coding language
Why Kotlin ?
• Not Functional language
• Combines OOP and Functional Programming
features
• Open source
• Targets JVM , Android and even JS
Why Kotlin ?
Kotlin for Android devs
Kotlin for Android devs
Kotlin has lots of advantages for #AndroiDev. By using
#Kotlin, my code is simply better for it. - Annyce Davis
I love #Kotlin. It's a breath of fresh air in the #AndroidDev world
- Donn Felker
At work we're just 100% on the #Kotlin train and yes, that
includes #AndroidDev production code! - Huyen Tue Dao
I enjoy writing in #Kotlin because I don't have to use a lot of
#AndroidDev 3rd party libraries - Dmytro Danylyk
#Kotlin enables more concise and understandable code without sacrificing performance
or safety - Dan Lew
Why Kotlin ?
Variables and properties
Syntax
val name: String ="John" //Immutable , its final
var name: String ="John" //Mutable
ex: name= "Johnny"
val name ="John" // Types are auto-inferred
val num: int =10 //Immediate assignment
var personList:List<String> = ArrayList() //Explicit type declaration
Syntax
Immutable
“Anything which will not change is val”
Mutable
“If value will be changed with time use var”
Rule of thumb
Modifiers - Class level
For members declared inside a class :
• Private - member is visible inside the class only.
• Protected - member has the same rules as private but is also available in
subclasses.
• Internal - any member inside the same module can see internal members
• Public - any member who can see the class can see it’s public members.
Default visibility is public
Modifiers - Top level
For declarations declared inside at the top level:
• Private - declaration only visible in the same file.
• Protected - not available as the top level is independent of any class
hierarchy.
• Internal - declaration visible only in the same module
• Public - declaration is visible everywhere
Default visibility is public
// Simple usage
val myValue = a
if (a < b) myValue = b
// As expression
val myValue = if ( a < b) a else b
// when replaces switch operator
when (x) {
1 -> print("First output")
2 -> print("Second output")
else -> {
print(" Nor 1 or 2 ") // This block :)
}
// for loop iterates with iterator
val list = listOf("Game of thrones","Breaking Bad","Gotham")
//while and do ..usual
while (x > 0) {
x--
}
do {
val y= someData()
} while( y!=100)
// Functions in Kotlin are declared using the fun keyword
fun sum (a: Int , b: Int) : Int {
return a + b
}
//or ..single line return
fun sum(a: Int , b: Int , c: Int) = a + b + c
//default values with functions
fun sum(a: Int , b: Int , c: Int , d: Int = 1) = a + b + c + d
Class - big picture
class Person(pName: String) {
var name: String = ""
var age: Int = -1
init {
this.name = pName
}
constructor(pName: String , pAge: Int) : this(pName) {
this.age = pAge
}
fun greet(): String {
return "Hello $name"
}
Class - big picture
class Person(pName: String) {
var name: String = ""
var age: Int = -1
init {
this.name = pName
}
constructor(pName: String , pAge: Int) : this(pName) {
this.age = pAge
}
fun greet(): String {
return "Hello $name"
}
// Instance , we call the constructor as if it were a
//regular function
val person = Person()
val me = Person("Adit")
// Kotlin - has no new keyword
Code
// The full syntax for declaring a property is
private var age:Int =0
get() = field
set(value) {
if(value>0)
field = value
}
internal fun sum(first: Int , second: Int): Int {
return first + second
}
Access modifier Keyword Name
Param name
Param type
Return type
Code
// Full syntax
internal fun sum(first: Int , second: Int): Int {
return first + second
}
// Omit access modifier
fun sum(first: Int , second: Int): Int {
return first + second
}
// Inline return
fun sum(first: Int , second: Int): Int = first + second
// Omit return type
fun sum(first: Int , second: Int) = first + second
// As a type
val sum - { first : Int, second: Int -> first + second }
Higher order functions
• Functions which return a function or take a function
as a parameter
• Used via Lambdas
• Java 6 support
NULL SAFETY
No more
Kotlin’s type system is aimed to eliminate this
forever.
Null Safety
var a: String = "abc"
a = null // compilation error
var b: String? = "abc"
b = null // ok
// what about this ?
val l = a.length // Promise no NPE crash
val l = b.length // error: b can be null
Null Safety
// You could explicitly check if b is null , and handle the options separately
val l = if (b!= null) b.length else -1
// Or ...
val length = b?.length
// Even better
val listWithNulls: List<String?> = listOf("A",null)
for (item in listWithNulls) {
item?.let { println(it)
} // prints A ignores null
Nullability
• In Java, the NullPointerException is one of the biggest headache’s
• Kotlin , ‘null’ is part of the type system
• We can explicitly declare a property , with nullable value
• For each function, we can declare whether it returns a nullable
value
• Goodbye, NullPointerException
Data classes
public class Movie {
private String name;
private String posterImgUrl;
private float rating;
public Movie(String name, String
imageUrl, float rating)
{
this.name = name;
this.posterImgUrl = imageUrl;
this.rating = rating;
}
// Getters and setters
// equals and hashCode
// toString()
}
Data classes
// Just use the keyword 'data' and see the magic
data class Movie(val name: String , val imgUrl:
String , val rating: Float)
val inception = Movie("Inception","http://
inception.com/poster.jpg",4.2)
print(inception.name)
print(inception.imgUrl)
print(inception.rating)
// Pretty print
print(inception.toString())
// Copy object
val inceptionTwo = inception.copy(imgUrl= "http://
imageUrl.com/inception2.png")
Fun tricks
fun evaluateObject(obj: Any): String {
return when(obj){
is String -> "String it is , ahoy !!"
is Int -> "Give me the 8 ball"
else -> "Object is in space"
}
}
fun ImageView.loadUrl(url: String) {
Glide.with(context).load(url).into(this)
}
Extensions
public static boolean isTuesday(Date date) {
return date.getDay() == 2;
}
boolean tuesdayBool =
DateUtils.isTuesday(date);
fun Date.isTuesday(): Boolean {
return getDay() ==2
}
val dateToCheck = Date()
println(date.isTuesday())
Lambdas
myButton.setOnClickListener { navigateToDetail() }
fun apply(one: Int , two: Int , func: (Int, Int) -> Int): Int{
return func(one,two)
}
println(apply(1, 2, { a, b -> a * b }))
println(apply(1, 2, { a, b -> a * 2 - 3 * b }))
Higher order Functions
if (obj instanceOf MyType) {
((MyType)obj).getXValue();
} else {
// Oh no do more
}
Smart Casting
if (obj is MyType) {
obj.getXValue()
} else {
// Oh no do more
}
… and More
• Visibility Modifiers
• Companion Objects
• Nested, Sealed Classes
• Generics
• Coroutines
• Operator overloading
• Exceptions
• Annotations
• Reflection
• and more
… and Even More
• Infix extension methods
• Interfaces
• Interface Delegation
• Property Delegation
• Destructuring
• Safe Singletons
• Init blocks
• Enums
• Multiline Strings
• Tail recursion
CODE
❤ Kotlin
Try Kotlin online
https://goo.gl/z9Hhq6
https://fabiomsr.github.io/from-java-to-kotlin/
QnA
THANK YOU
@aditlal

More Related Content

What's hot (20)

PPT
The Kotlin Programming Language
intelliyole
 
PDF
Kotlin - Better Java
Dariusz Lorenc
 
PDF
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
PDF
Kotlin in action
Ciro Rizzo
 
PDF
Kotlin boost yourproductivity
nklmish
 
PDF
Kotlin: Why Do You Care?
intelliyole
 
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
PDF
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
PPTX
Introduction to Koltin for Android Part I
Atif AbbAsi
 
PDF
Swift and Kotlin Presentation
Andrzej Sitek
 
PDF
Kotlin: Challenges in JVM language design
Andrey Breslav
 
PDF
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
PDF
Taking Kotlin to production, Seriously
Haim Yadid
 
PDF
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
PDF
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
ODP
From object oriented to functional domain modeling
Codemotion
 
PDF
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
PDF
Introduction to kotlin
NAVER Engineering
 
PPTX
Kotlin
Rory Preddy
 
PDF
Kotlin hands on - MorningTech ekito 2017
Arnaud Giuliani
 
The Kotlin Programming Language
intelliyole
 
Kotlin - Better Java
Dariusz Lorenc
 
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
Kotlin in action
Ciro Rizzo
 
Kotlin boost yourproductivity
nklmish
 
Kotlin: Why Do You Care?
intelliyole
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Swift and Kotlin Presentation
Andrzej Sitek
 
Kotlin: Challenges in JVM language design
Andrey Breslav
 
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Taking Kotlin to production, Seriously
Haim Yadid
 
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
From object oriented to functional domain modeling
Codemotion
 
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
Introduction to kotlin
NAVER Engineering
 
Kotlin
Rory Preddy
 
Kotlin hands on - MorningTech ekito 2017
Arnaud Giuliani
 

Similar to Kotlin for Android devs (20)

PDF
Privet Kotlin (Windy City DevFest)
Cody Engel
 
PDF
Kotlin what_you_need_to_know-converted event 4 with nigerians
junaidhasan17
 
PDF
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
PDF
Exploring Kotlin
Johan Haleby
 
PPTX
Kotlin Basic & Android Programming
Kongu Engineering College, Perundurai, Erode
 
PPTX
Kotlin as a Better Java
Garth Gilmour
 
PDF
Kotlin for Android Developers - 3
Mohamed Nabil, MSc.
 
PPTX
Exploring Kotlin language basics for Android App development
Jayaprakash R
 
PDF
Be More Productive with Kotlin
Brandon Wever
 
PDF
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
PPTX
Introduction to Kotlin for Android developers
Mohamed Wael
 
PDF
9054799 dzone-refcard267-kotlin
Zoran Stanimirovic
 
PPTX
Hello kotlin | An Event by DSC Unideb
Muhammad Raza
 
PDF
Intro to Kotlin
Magda Miu
 
PPTX
Introduction to kotlin and OOP in Kotlin
vriddhigupta
 
PDF
Exploring Koltin on Android
Deepanshu Madan
 
PDF
2 kotlin vs. java: what java has that kotlin does not
Sergey Bandysik
 
PPTX
kotlin-nutshell.pptx
AbdulRazaqAnjum
 
PPTX
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
PDF
Compose Camp - Session1.pdf
GDSCAtharvaCollegeOf
 
Privet Kotlin (Windy City DevFest)
Cody Engel
 
Kotlin what_you_need_to_know-converted event 4 with nigerians
junaidhasan17
 
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
Exploring Kotlin
Johan Haleby
 
Kotlin Basic & Android Programming
Kongu Engineering College, Perundurai, Erode
 
Kotlin as a Better Java
Garth Gilmour
 
Kotlin for Android Developers - 3
Mohamed Nabil, MSc.
 
Exploring Kotlin language basics for Android App development
Jayaprakash R
 
Be More Productive with Kotlin
Brandon Wever
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
Introduction to Kotlin for Android developers
Mohamed Wael
 
9054799 dzone-refcard267-kotlin
Zoran Stanimirovic
 
Hello kotlin | An Event by DSC Unideb
Muhammad Raza
 
Intro to Kotlin
Magda Miu
 
Introduction to kotlin and OOP in Kotlin
vriddhigupta
 
Exploring Koltin on Android
Deepanshu Madan
 
2 kotlin vs. java: what java has that kotlin does not
Sergey Bandysik
 
kotlin-nutshell.pptx
AbdulRazaqAnjum
 
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
Compose Camp - Session1.pdf
GDSCAtharvaCollegeOf
 
Ad

Recently uploaded (20)

PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Ad

Kotlin for Android devs

  • 1. K O T L I N ANDROID Kotlin for Android dev
  • 2. 100 % interoperable with Java Kotlin for Android devs Developed by JetBrains KOTLIN
  • 3. KOTLIN 2010 - Work Started 2011 - Announced 2016 - 1.0 release 2017 - 1.1 release Official Android First Class Language
  • 4. Agenda What is Kotlin ? Kotlin for Android devs Why Kotlin ? Syntax crash course Features of Kotlin QnA Hands-on Session
  • 7. • Null references are controlled by the type system. • No raw types • Arrays in Kotlin are invariant • Kotlin has proper function types, as opposed to Java’s SAM-conversions • Use-site variance without wildcards • Kotlin does not have checked exceptions Kotlin fixes a series of issues that Java suffers from
  • 8. Checked exceptions Primitive types that are not classes Static members Non-private fields Wildcard-types What Java has that Kotlin does not
  • 9. KOTLIN & ANDROID Kotlin can be updated independently from the OS.
  • 10. OOP language with functional aspects Modern and powerful language Focuses on safe concise and readable code Its a statically-typed programming language What is Kotlin ? First class tool support
  • 11. Statically typed programming language for the JVM, Android and the browser What is Kotlin ? Its a statically-typed programming language
  • 13. What we get by using Java 6/7 + Android - • Inability to add methods in platform APIs , have to use Utils • NO Lambdas , NO Streams • NPE - so many of them What we need We need modern and smart coding language Why Kotlin ?
  • 14. • Not Functional language • Combines OOP and Functional Programming features • Open source • Targets JVM , Android and even JS Why Kotlin ?
  • 17. Kotlin has lots of advantages for #AndroiDev. By using #Kotlin, my code is simply better for it. - Annyce Davis I love #Kotlin. It's a breath of fresh air in the #AndroidDev world - Donn Felker At work we're just 100% on the #Kotlin train and yes, that includes #AndroidDev production code! - Huyen Tue Dao I enjoy writing in #Kotlin because I don't have to use a lot of #AndroidDev 3rd party libraries - Dmytro Danylyk #Kotlin enables more concise and understandable code without sacrificing performance or safety - Dan Lew
  • 19. Variables and properties Syntax val name: String ="John" //Immutable , its final var name: String ="John" //Mutable ex: name= "Johnny" val name ="John" // Types are auto-inferred val num: int =10 //Immediate assignment var personList:List<String> = ArrayList() //Explicit type declaration
  • 20. Syntax Immutable “Anything which will not change is val” Mutable “If value will be changed with time use var” Rule of thumb
  • 21. Modifiers - Class level For members declared inside a class : • Private - member is visible inside the class only. • Protected - member has the same rules as private but is also available in subclasses. • Internal - any member inside the same module can see internal members • Public - any member who can see the class can see it’s public members. Default visibility is public
  • 22. Modifiers - Top level For declarations declared inside at the top level: • Private - declaration only visible in the same file. • Protected - not available as the top level is independent of any class hierarchy. • Internal - declaration visible only in the same module • Public - declaration is visible everywhere Default visibility is public
  • 23. // Simple usage val myValue = a if (a < b) myValue = b // As expression val myValue = if ( a < b) a else b
  • 24. // when replaces switch operator when (x) { 1 -> print("First output") 2 -> print("Second output") else -> { print(" Nor 1 or 2 ") // This block :) }
  • 25. // for loop iterates with iterator val list = listOf("Game of thrones","Breaking Bad","Gotham") //while and do ..usual while (x > 0) { x-- } do { val y= someData() } while( y!=100)
  • 26. // Functions in Kotlin are declared using the fun keyword fun sum (a: Int , b: Int) : Int { return a + b } //or ..single line return fun sum(a: Int , b: Int , c: Int) = a + b + c //default values with functions fun sum(a: Int , b: Int , c: Int , d: Int = 1) = a + b + c + d
  • 27. Class - big picture class Person(pName: String) { var name: String = "" var age: Int = -1 init { this.name = pName } constructor(pName: String , pAge: Int) : this(pName) { this.age = pAge } fun greet(): String { return "Hello $name" }
  • 28. Class - big picture class Person(pName: String) { var name: String = "" var age: Int = -1 init { this.name = pName } constructor(pName: String , pAge: Int) : this(pName) { this.age = pAge } fun greet(): String { return "Hello $name" } // Instance , we call the constructor as if it were a //regular function val person = Person() val me = Person("Adit") // Kotlin - has no new keyword
  • 29. Code // The full syntax for declaring a property is private var age:Int =0 get() = field set(value) { if(value>0) field = value } internal fun sum(first: Int , second: Int): Int { return first + second } Access modifier Keyword Name Param name Param type Return type
  • 30. Code // Full syntax internal fun sum(first: Int , second: Int): Int { return first + second } // Omit access modifier fun sum(first: Int , second: Int): Int { return first + second } // Inline return fun sum(first: Int , second: Int): Int = first + second // Omit return type fun sum(first: Int , second: Int) = first + second // As a type val sum - { first : Int, second: Int -> first + second }
  • 31. Higher order functions • Functions which return a function or take a function as a parameter • Used via Lambdas • Java 6 support
  • 32. NULL SAFETY No more Kotlin’s type system is aimed to eliminate this forever.
  • 33. Null Safety var a: String = "abc" a = null // compilation error var b: String? = "abc" b = null // ok // what about this ? val l = a.length // Promise no NPE crash val l = b.length // error: b can be null
  • 34. Null Safety // You could explicitly check if b is null , and handle the options separately val l = if (b!= null) b.length else -1 // Or ... val length = b?.length // Even better val listWithNulls: List<String?> = listOf("A",null) for (item in listWithNulls) { item?.let { println(it) } // prints A ignores null
  • 35. Nullability • In Java, the NullPointerException is one of the biggest headache’s • Kotlin , ‘null’ is part of the type system • We can explicitly declare a property , with nullable value • For each function, we can declare whether it returns a nullable value • Goodbye, NullPointerException
  • 36. Data classes public class Movie { private String name; private String posterImgUrl; private float rating; public Movie(String name, String imageUrl, float rating) { this.name = name; this.posterImgUrl = imageUrl; this.rating = rating; } // Getters and setters // equals and hashCode // toString() }
  • 37. Data classes // Just use the keyword 'data' and see the magic data class Movie(val name: String , val imgUrl: String , val rating: Float) val inception = Movie("Inception","http:// inception.com/poster.jpg",4.2) print(inception.name) print(inception.imgUrl) print(inception.rating) // Pretty print print(inception.toString()) // Copy object val inceptionTwo = inception.copy(imgUrl= "http:// imageUrl.com/inception2.png")
  • 38. Fun tricks fun evaluateObject(obj: Any): String { return when(obj){ is String -> "String it is , ahoy !!" is Int -> "Give me the 8 ball" else -> "Object is in space" } } fun ImageView.loadUrl(url: String) { Glide.with(context).load(url).into(this) }
  • 39. Extensions public static boolean isTuesday(Date date) { return date.getDay() == 2; } boolean tuesdayBool = DateUtils.isTuesday(date); fun Date.isTuesday(): Boolean { return getDay() ==2 } val dateToCheck = Date() println(date.isTuesday())
  • 40. Lambdas myButton.setOnClickListener { navigateToDetail() } fun apply(one: Int , two: Int , func: (Int, Int) -> Int): Int{ return func(one,two) } println(apply(1, 2, { a, b -> a * b })) println(apply(1, 2, { a, b -> a * 2 - 3 * b })) Higher order Functions
  • 41. if (obj instanceOf MyType) { ((MyType)obj).getXValue(); } else { // Oh no do more } Smart Casting if (obj is MyType) { obj.getXValue() } else { // Oh no do more }
  • 42. … and More • Visibility Modifiers • Companion Objects • Nested, Sealed Classes • Generics • Coroutines • Operator overloading • Exceptions • Annotations • Reflection • and more
  • 43. … and Even More • Infix extension methods • Interfaces • Interface Delegation • Property Delegation • Destructuring • Safe Singletons • Init blocks • Enums • Multiline Strings • Tail recursion
  • 44. CODE ❤ Kotlin Try Kotlin online https://goo.gl/z9Hhq6 https://fabiomsr.github.io/from-java-to-kotlin/
  • 45. QnA