Recap
Recap what you learned about Kotlin, its principles, and how they drive language features.
We'll cover the following...
You now have a solid understanding of the basics of Kotlin. Before we explore ways to continue your Kotlin journey, let’s briefly recap all that you learned in this course. After all, repetition is one of the keys to learning.
Variables and Mutable Types #
- Kotlin favors the use of read-only variables.
- Use
val
to create a read-only variable. - Use
var
to create a mutable variable. - First, note how declaring a read-only variable takes no more characters than a mutable one, in contrast to many other languages (e.g., Java requiring the
final
modifier). - Second, note that variable names in your code are usually nicely aligned because the two keywords have the same number of characters.
- Use
- In alignment with this, Kotlin also differentiates between read-only and mutable collection types, again favoring the use of read-only ones.
- For instance, a simple
listOf(...)
will give you a read-only list. - To get a mutable list, you have to explicitly write
mutableListOf(...)
, making read-only the default case.
- For instance, a simple