SlideShare a Scribd company logo
1 of 23
Download to read offline
Kotlin 

A nova linguagem oficial do Android
GDGFoz
Quem ?
• Houssan Ali Hijazi - hussanhijazi@gmail.com
• Desenvolvedor Android na www.HElabs.com
• Organizador GDG Foz do Iguaçu
• www.lojasnoparaguai.com.br
• www.desaparecidosbr.org
• www.hussan.com.br
GDGFoz
Kotlin
• 2011/JetBrains
• 1.0 em Fev. 2016
• 1.1 em Mar. 2017
• Pinterest, Coursera, Netflix, Uber, Square, Trello e
Basecamp
• Google IO 2017
GDGFoz
Kotlin
GDGFoz
Kotlin
• Interoperabilidade
• Null Safety
• Conciso
GDGFoz
Properties/Fields
val name: String = "João"
val name = "João"
GDGFoz
val/var
val user = User()
user = User() // :(
var user = User()
user = User() // :)
GDGFoz
Null Safety/Safe Calls
var name: String? = "José"

println(name?.length)
var name: String = "José"
name = null // :(
var name: String? = "José"

name = null // :)

val lastName: String? = null
GDGFoz
Elvis Operator
val name: String? = "José"
val c: Int = if (name != null) name.length else -1
val c = name?.length ?: -1
GDGFoz
Class
class Car(val name: String = ""): Vehicle() {
constructor(name: String, color: String) : this(name) {
}
}
GDGFoz
Kotlin
class Car
{ 

private String name;
public String getName()
{
//...
}
public void setName(String s)
{
//...
}
}
// ^^Java
// vv Kotlin
val car = Car()
println("Name: ${car.name}")
GDGFoz
Functions
fun calculate(num: Int, num2: Int = 10): Int
{
return num + num2
}
fun calculate(num: Int, num2: Int): Int
= num + num2

fun calculate(num: Int, num2: Int)
= num + num2
calculate(num = 10, num2 = 20)
GDGFoz
Interface
interface BaseView {
fun bar()
fun foo() {
// optional body
}
}
class View : BaseView {
override fun bar() {
}
}
GDGFoz
Data Class
data class Truck(val name:String, val color: String
= "Red")
GDGFoz
For/Range
// prints number from 1 through 10
for (i in 1..10) {
print(i)
}
// prints 100, 98, 96 ...
for (i in 100 downTo 1 step 2) {
print(i)
}



for (item in collection) print(item)
GDGFoz
When
when (x) {
in 1..10 -> print("x is in the range")
!in 10..20 -> print("x is outside the range")
else -> print("none of the above")
}
fun hasPrefix(x: Any) = when(x) {
is String -> x.startsWith("prefix")
else -> false
}
when (x) {
1 -> print("x == 1")
2 -> print("x == 2")
else -> {
print("x is neither 1 nor 2")
}
}

GDGFoz
Collections
val set = hashSetOf(1, 2, 3)
val list = arrayListOf(1, 2, 3)
val items = listOf(1, 2, 3, 4)
items.first() == 1
items.last() == 4
items.filter { it % 2 == 0 } // returns [2, 4]
items.forEach { println(it) }
// count, forEachIndexed, max, min, take, slice, map, flatMap
… etc.. 

// More in https://antonioleiva.com/collection-operations-
kotlin/
GDGFoz
Lambdas
showButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View button) {
text.setVisibility(View.VISIBLE)
button.setBackgroundColor(ContextCompat.getColor(this,
R.color.colorAccent))
}
});

// ^^ Java
showButton.setOnClickListener { button ->
text.visibility = View.VISIBLE
button.setBackgroundColor(ContextCompat.getColor(thi
s, R.color.colorAccent))
}
// ^^Kotlin
GDGFoz
Lambdas
// ^^ Class
validate(this::toast)
fun validate(callback: () -> Unit)
{
// validate
callback.invoke()
}
fun toast() {
val toast = Toast.makeText(this, "Callback called",
Toast.LENGTH_LONG)
toast.show()
}
GDGFoz
let/with
var name: String? = "João"


name?.let {
println(it.toUpperCase())
println(it.length)
}
with(name) {
println(toUpperCase())
println(length)
}

// See: apply/run
GDGFoz
Infix
infix fun String.drive(car: String) =
Pair(this, car)

val usersCars = mapOf("José" drive "Fusca",
"João" drive "Ferrari")


val usersCars2 =
mapOf("José".drive("Fusca"),
"João".drive("Ferrari"));
val (driver, car) = "José" drive "Fusca"
GDGFoz
Extensions
fun View.hide()
{
visibility = View.GONE
}
fun View.show()
{
visibility = View.VISIBLE
}
button.setVisibility(View.VISIBLE)
var button: Button = findViewById(R.id.button) as
Button
button.hide()
Obrigado

More Related Content

What's hot (8)

Ececececuacion de primer grado y
Ececececuacion de primer grado yEcecececuacion de primer grado y
Ececececuacion de primer grado y
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
contoh Program queue
contoh Program queuecontoh Program queue
contoh Program queue
 
Searching Billions of Documents with Redis
Searching Billions of Documents with RedisSearching Billions of Documents with Redis
Searching Billions of Documents with Redis
 
20090622 Vimm4
20090622 Vimm420090622 Vimm4
20090622 Vimm4
 
Code
CodeCode
Code
 
Rumus VB Menghitung Nilai Persamaan
Rumus VB Menghitung Nilai PersamaanRumus VB Menghitung Nilai Persamaan
Rumus VB Menghitung Nilai Persamaan
 
RediSearch
RediSearchRediSearch
RediSearch
 

Similar to Kotlin, a nova linguagem oficial do Android

Similar to Kotlin, a nova linguagem oficial do Android (20)

Why Kotlin is your next language?
Why Kotlin is your next language? Why Kotlin is your next language?
Why Kotlin is your next language?
 
Intro to kotlin 2018
Intro to kotlin 2018Intro to kotlin 2018
Intro to kotlin 2018
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming course
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora
 
Grails Launchpad - From Ground Zero to Orbit
Grails Launchpad - From Ground Zero to OrbitGrails Launchpad - From Ground Zero to Orbit
Grails Launchpad - From Ground Zero to Orbit
 
What's in Groovy for Functional Programming
What's in Groovy for Functional ProgrammingWhat's in Groovy for Functional Programming
What's in Groovy for Functional Programming
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutes
 
PyDX Presentation about Python, GeoData and Maps
PyDX Presentation about Python, GeoData and MapsPyDX Presentation about Python, GeoData and Maps
PyDX Presentation about Python, GeoData and Maps
 
C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607
 
Institute management
Institute managementInstitute management
Institute management
 
No excuses, switch to kotlin
No excuses, switch to kotlinNo excuses, switch to kotlin
No excuses, switch to kotlin
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
 
Kotlin : Happy Development
Kotlin : Happy DevelopmentKotlin : Happy Development
Kotlin : Happy Development
 
Mongo db dla administratora
Mongo db dla administratoraMongo db dla administratora
Mongo db dla administratora
 
Poly-paradigm Java
Poly-paradigm JavaPoly-paradigm Java
Poly-paradigm Java
 
ProgrammingwithGOLang
ProgrammingwithGOLangProgrammingwithGOLang
ProgrammingwithGOLang
 
Learning groovy -EU workshop
Learning groovy  -EU workshopLearning groovy  -EU workshop
Learning groovy -EU workshop
 

More from GDGFoz

Dart e Flutter do Server ao Client Side
Dart e Flutter do Server ao Client SideDart e Flutter do Server ao Client Side
Dart e Flutter do Server ao Client Side
GDGFoz
 

More from GDGFoz (20)

Apresentação GDG Foz 2023
Apresentação GDG Foz  2023Apresentação GDG Foz  2023
Apresentação GDG Foz 2023
 
Desenvolvimento de um Comedouro para cães com Acionamento Automático e Remoto
Desenvolvimento de um Comedouro para cães com Acionamento Automático e RemotoDesenvolvimento de um Comedouro para cães com Acionamento Automático e Remoto
Desenvolvimento de um Comedouro para cães com Acionamento Automático e Remoto
 
Introdução do DEVSECOPS
Introdução do DEVSECOPSIntrodução do DEVSECOPS
Introdução do DEVSECOPS
 
Aquisição de dados IoT com Event Sourcing e Microservices
Aquisição de dados IoT com Event Sourcing e MicroservicesAquisição de dados IoT com Event Sourcing e Microservices
Aquisição de dados IoT com Event Sourcing e Microservices
 
Robótica Sucational
Robótica SucationalRobótica Sucational
Robótica Sucational
 
A nova era do desenvolvimento mobile
A nova era do desenvolvimento mobile A nova era do desenvolvimento mobile
A nova era do desenvolvimento mobile
 
Qualidade em Testes de Software
Qualidade em Testes de SoftwareQualidade em Testes de Software
Qualidade em Testes de Software
 
WebAssembly além da Web - Casos de Uso em IoT
WebAssembly além da Web - Casos de Uso em IoTWebAssembly além da Web - Casos de Uso em IoT
WebAssembly além da Web - Casos de Uso em IoT
 
Dart e Flutter do Server ao Client Side
Dart e Flutter do Server ao Client SideDart e Flutter do Server ao Client Side
Dart e Flutter do Server ao Client Side
 
UX: O que é e como pode influenciar a vida do desenvolvedor?
UX: O que é e como pode influenciar a vida do desenvolvedor?UX: O que é e como pode influenciar a vida do desenvolvedor?
UX: O que é e como pode influenciar a vida do desenvolvedor?
 
Dicas de como entrar no mundo do DevSecOps
Dicas de como entrar no mundo do DevSecOpsDicas de como entrar no mundo do DevSecOps
Dicas de como entrar no mundo do DevSecOps
 
Angular >= 2 - One Framework Mobile & Desktop
Angular >= 2 - One Framework Mobile & DesktopAngular >= 2 - One Framework Mobile & Desktop
Angular >= 2 - One Framework Mobile & Desktop
 
Automação Residencial Extrema com Opensource
Automação Residencial Extrema com OpensourceAutomação Residencial Extrema com Opensource
Automação Residencial Extrema com Opensource
 
Brasil.IO COVID-19: Dados por Municípios. Quais os Desafios?
Brasil.IO COVID-19: Dados por Municípios. Quais os Desafios?Brasil.IO COVID-19: Dados por Municípios. Quais os Desafios?
Brasil.IO COVID-19: Dados por Municípios. Quais os Desafios?
 
Desmistificando a programação funcional
Desmistificando a programação funcionalDesmistificando a programação funcional
Desmistificando a programação funcional
 
Microsserviços com Kotlin
Microsserviços com KotlinMicrosserviços com Kotlin
Microsserviços com Kotlin
 
Autenticação de dois fatores
Autenticação de dois fatores Autenticação de dois fatores
Autenticação de dois fatores
 
Fique em casa seguro (ou tente)!
Fique em casa seguro (ou tente)!Fique em casa seguro (ou tente)!
Fique em casa seguro (ou tente)!
 
Hooks em React: o novo jeito de fazer componentes funcionais
Hooks em React: o novo jeito de fazer componentes funcionaisHooks em React: o novo jeito de fazer componentes funcionais
Hooks em React: o novo jeito de fazer componentes funcionais
 
Angular, React ou Vue? Comparando os favoritos do JS reativo
Angular, React ou Vue? Comparando os favoritos do JS reativoAngular, React ou Vue? Comparando os favoritos do JS reativo
Angular, React ou Vue? Comparando os favoritos do JS reativo
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (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)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Kotlin, a nova linguagem oficial do Android