Construindo o primeiro app
usando Kotlin
Filipe Guedes Philipe Steiff
@fgsguedes @philipesteiff
Por que Kotlin?
• Concisa, simples e fácil de ler/escrever
• 100% "two-way" interoperável com Java
• Também é funcional
• ...
class Foo {



fun sum(a: Int, b: Int): Int {

return a + b

}



fun printSum(a: Int, b: Int): Unit {

print(a + b)

}


...
class Foo {



fun sum(a: Int, b: Int) = a + b




fun printSum(a: Int, b: Int) {

print(a + b)

}



}
val a: Int = 1



val b = 1



var c = "Any variable"



val d = Foo()
Null Safety
var a: String = "abc"

Null Safety
var a: String = "abc"

a = null
Null Safety
var a: String = "abc"

a = null // compilation error
Null Safety
var a: String = "abc"

a = null // compilation error



println(a.length)
Null Safety
var a: String? = "abc"

a = null



println(a.length)
Null Safety
var a: String? = "abc"

a = null



println(a.length)
// compilation error
Null Safety
var a: String? = "abc"

a = null



println(a?.length)
Null Safety
var a: String? = "abc"

a = null



println(a?.length)
// will print 'null'
Null Safety
var a: String? = "abc"

a = null



println(a?.length ?: "Was null")
// will print 'Was null'
Null Safety
var a: String? = "abc"

a = null



println(a!!.length)
// XGH
Extensions
fun Parcel.readBoolean() = readByte() > 0


fun Parcel.writeBoolean(boolean: Boolean) {

when {

boolean -> wri...
Quem está usando!?
Some live coding!!
Wish us luck
Upcoming SlideShare
Loading in …5
×

Android DevConference - Live code with Kotlin: construindo o primeiro app usando Kotlin

69 views

Published on

Filipe Guedes e Philipe Steiff, 99 Taxi, falam sobre Live code with Kotlin: construindo o primeiro app usando Kotlin no Android DevConference 2016. Saiba mais em: http://androidconference.com.br/

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
69
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android DevConference - Live code with Kotlin: construindo o primeiro app usando Kotlin

  1. 1. Construindo o primeiro app usando Kotlin Filipe Guedes Philipe Steiff @fgsguedes @philipesteiff
  2. 2. Por que Kotlin? • Concisa, simples e fácil de ler/escrever • 100% "two-way" interoperável com Java • Também é funcional • Null-safety • Extension functions • It's fun
  3. 3. class Foo {
 
 fun sum(a: Int, b: Int): Int {
 return a + b
 }
 
 fun printSum(a: Int, b: Int): Unit {
 print(a + b)
 }
 
 }
  4. 4. class Foo {
 
 fun sum(a: Int, b: Int) = a + b 
 
 fun printSum(a: Int, b: Int) {
 print(a + b)
 }
 
 }
  5. 5. val a: Int = 1
 
 val b = 1
 
 var c = "Any variable"
 
 val d = Foo()
  6. 6. Null Safety var a: String = "abc"

  7. 7. Null Safety var a: String = "abc"
 a = null
  8. 8. Null Safety var a: String = "abc"
 a = null // compilation error
  9. 9. Null Safety var a: String = "abc"
 a = null // compilation error
 
 println(a.length)
  10. 10. Null Safety var a: String? = "abc"
 a = null
 
 println(a.length)
  11. 11. Null Safety var a: String? = "abc"
 a = null
 
 println(a.length) // compilation error
  12. 12. Null Safety var a: String? = "abc"
 a = null
 
 println(a?.length)
  13. 13. Null Safety var a: String? = "abc"
 a = null
 
 println(a?.length) // will print 'null'
  14. 14. Null Safety var a: String? = "abc"
 a = null
 
 println(a?.length ?: "Was null") // will print 'Was null'
  15. 15. Null Safety var a: String? = "abc"
 a = null
 
 println(a!!.length) // XGH
  16. 16. Extensions fun Parcel.readBoolean() = readByte() > 0 
 fun Parcel.writeBoolean(boolean: Boolean) {
 when {
 boolean -> writeByte(1)
 else -> writeByte(0)
 }
 } override fun writeToParcel(parcel: Parcel, p1: Int) {
 parcel.writeBoolean(myBooleanField)
 } myBooleanField = parcel.readBoolean()
  17. 17. Quem está usando!?
  18. 18. Some live coding!! Wish us luck

×