Lack of static
Kotlin doesn't have a static keyword, so what should you do if you want your code to be written in Kotlin, but still adhere to patterns and conventions that require static, or at least the appearance of static? There are a few different options for these cases.
One of the more common uses of static methods and fields is for things such as helper functions and constants. In Java, it's common to have classes that exist for the sole purpose of containing static methods or fields. In Kotlin, these types of static methods/fields, and their associated classes, can be replaced with things such as top-level functions and properties, extension functions, or companion objects. We'll look at these in depth later in the chapter.
The Kotlin ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access