I'm starting to learn Kotlin. I'm pretty sure a large majority of all Android devs are also doing this right now. There are plenty of blog posts, videos, podcasts, talks etc. etc. being produced. Rather than doing another learn X or whatever about Kotlin blog post, my intention is to post things here that I've found particularly interesting or useful. Therefore, what you're reading is incomplete, may never be completed and might make no f***ing sense. But I'm keen to get things down so that I have something to come back to. And maybe you might find it interesting as well. Or not. It doesn't matter, this isn't for you, this is for future Mike 👋 (Remember to fry the pillow)
Beginner resources
Blog posts
- Introduction to Kotlin
- Kotlin Programming Language Cheat Sheet Part 1
- Mastering Kotlin: A practical guide for Android devs
Advanced Resources
Blog posts
Courses
Language Features
Properties
What's the difference between a field
in Java and a property
in Kotlin? There's a lot more to a property in Kotlin, the default includes accessors and you can even do propert delegation. This article explains it all well.
List
Usually in Java I would new up an ArrayList
and then add
everything I needed to it, line after line after line...No more! While you can do it that way in Kotlin, you can also do this:
val strings = arrayListOf("Android", "Snacks", "Rocks)
This will give me an ArrayList
of String
without the need for all those extra lines. There's also listOf
, mutableListOf
, listOfNotNull
and emptyList
.
Singletons
Singleton with single argument
If you need to create a Singleton with an argument then you need to check out this blog post by Christoper Beyls which shows how to implement a double locking mechanism in Kotlin.
Sealed Classes
This is a great example (and explanation) on how they can be used to handle success and errors in an RxJava stream.
https://antonioleiva.com/sealed-classes-kotlin/
Inlining
Properties in Kotlin can be inlined! this will help produce more optimal bytecode.
https://blog.egorand.me/inlining-kotlin-properties/
Custom Property Delegates
https://robots.thoughtbot.com/kotlin-is-dope-and-so-are-its-custom-property-delegates
https://blog.kotlin-academy.com/superpowers-of-kotlin-delegation-e6bd9ff8026c
@JvmSuppressWildcards
http://adavis.info/2017/08/jvmsuppresswildcards-biggest-annoyance-kotlin.html
Run, with, let, also and apply
Gotchas
https://medium.com/@xzan/the-drawbacks-of-migrating-to-kotlin-51f49a96107a