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)
- Introduction to Kotlin
- Kotlin Programming Language Cheat Sheet Part 1
- Mastering Kotlin: A practical guide for Android devs
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.
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
String without the need for all those extra lines. There's also
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.
This is a great example (and explanation) on how they can be used to handle success and errors in an RxJava stream.
Properties in Kotlin can be inlined! this will help produce more optimal bytecode.