Constants

Kotlin has a const keyword, which you can use to declare certain val properties as constants. This is somewhat reminiscent of final in Java.

This may seem a bit odd. After all, by many definitions, val already is a constant. You cannot change its value, after all.

There are some reasons for having const, though, but we will hold off on those until much later in the book. For now, if while reading Kotlin code you see the const keyword, just imagine that it means “no, really, I mean that this should be a constant”.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.