SlideShare a Scribd company logo
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

PPTX
How i won a golf set from reg.ru
PDF
Learning ProcessingJS
PDF
Coding with Vim
PPTX
PDF
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
PPTX
Full Presentation on Notepad
PDF
メディアアートにおけるプログラミング言語Rubyの役割
How i won a golf set from reg.ru
Learning ProcessingJS
Coding with Vim
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Full Presentation on Notepad
メディアアートにおけるプログラミング言語Rubyの役割

What's hot (8)

DOC
Ececececuacion de primer grado y
PPTX
Oprerator overloading
DOCX
contoh Program queue
PDF
Searching Billions of Documents with Redis
PDF
20090622 Vimm4
DOC
Rumus VB Menghitung Nilai Persamaan
PDF
RediSearch
Ececececuacion de primer grado y
Oprerator overloading
contoh Program queue
Searching Billions of Documents with Redis
20090622 Vimm4
Rumus VB Menghitung Nilai Persamaan
RediSearch
Ad

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

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

More from GDGFoz (20)

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

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Machine Learning_overview_presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Tartificialntelligence_presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
20250228 LYD VKU AI Blended-Learning.pptx
A comparative analysis of optical character recognition models for extracting...
Assigned Numbers - 2025 - Bluetooth® Document
Advanced methodologies resolving dimensionality complications for autism neur...
Machine Learning_overview_presentation.pptx
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Tartificialntelligence_presentation.pptx
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Group 1 Presentation -Planning and Decision Making .pptx

Kotlin, a nova linguagem oficial do Android