Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Why Kotlin makes Java null and void

186 views

Published on

Why using Kotlin instead of Java, especially for Android, is a great idea. Presented at Brighton Mobile Feb 2018

Published in: Software
  • Be the first to comment

  • Be the first to like this

Why Kotlin makes Java null and void

  1. 1. Kotlin makes Java Null and Void @chetbox
  2. 2. Who is this guy?
  3. 3. Firebase +
  4. 4. You can use Kotlin in production today
  5. 5. fun main(args: Array<String>) { println("Hello, world!") }
  6. 6. Optional types
  7. 7. var name: String? = … val name: String = …
  8. 8. println(name!!) println(name.length)
  9. 9. @NonNull @Nullable
  10. 10. Classes
  11. 11. class Foo { }
  12. 12. class MyModel( foo: Int, val bar: Int, private var baz: Int )
  13. 13. data class LatLng( val lat: Double, val lng: Double )
  14. 14. Java interop
  15. 15. class Foo { companion object { fun bar() { … } } }
  16. 16. // From Kotlin Foo.bar()
  17. 17. // From Java Foo.Companion.bar()
  18. 18. Functional programming
  19. 19. listOf(1 to "one", 2 to "2", null) .filterNotNull() .map { (a, b) -> "$a" == b }
  20. 20. inline fun log(f: () -> String) { println(“${time()}: ${f()}“) ) log(readMsg) log { “Got value: ${readMsg()}” }
  21. 21. Extension functions
  22. 22. fun List<Location>.totalDistance() = zipWithNext() .fold(0f) { total, (current, next) -> total + current.distanceTo(next) }
  23. 23. How do I convert my Java project to Kotlin?
  24. 24. IntelliJ is your Sensei Converting “var” to “val” “when” clauses Optional types Idiomatic Kotlin
  25. 25. It looks like you’re pasting Java code. Shall I convert it to Kotlin for you?
  26. 26. Kotlin > Java Shorter code ✂ Null safety Easy Java interop ↔ First-class IDE support from IntelliJ Lot of libraries are now being written in Kotlin Official Android examples in Java and Kotlin
  27. 27. Kotlin vs. Swift
  28. 28. func double( _ numbers: [Int] ) -> [Int] { return numbers.map { 2 * $0 } } let numbers: [Int] = 1 ... 10 print(double(numbers))
  29. 29. fun double( numbers: List<Int> ) : List<Int> { return numbers.map { 2 * it } } val numbers = 1 .. 10 println(double(numbers))
  30. 30. fun double( numbers: List<Number> ) = numbers.map { 2 * it } val numbers = 1 .. 10 println(double(numbers))
  31. 31. val numbers = 1..10 println(numbers.map { 2 * it })
  32. 32. Learn more Talk: Kotlin in Production Talk: Life is Great and Everything Will Be Ok, Kotlin is Here Swift is like Kotlin Christina Lee - Pinterest Jake Wharton - Google Kotlinlang Slack Fragmented podcast Talking Kotlin podcast
  33. 33. Questions? Or find me on Twitter: @chetbox

×