Kotlin companion object - common use cases

138 Просмотры
Издатель
The companion object allows you to have properties or functions without having an instance of the class. There are no static variables in Kotlin, so this is how you achieve the same thing.

Programming Kotlin by Venkat Subramaniam: https://amzn.to/3sNnryh
https://discuss.kotlinlang.org/t/what-is-the-advantage-of-companion-object-vs-static-keyword/4034/7

Hi! I’m Rahul, a software engineer with a passion for teaching. I went to Stanford, was a founding engineer at a startup, and have worked at various companies across Silicon Valley. I’m currently an Android Developer at Facebook and teach an Android class at Stanford. Would love to connect with you! This channel is about tech (especially Silicon Valley), combining tactical how-to guides with interviews.

Категория
Язык программирования Kotlin
Комментариев нет.