Mastering Companion Objects in Kotlin: Revision history

Jump to navigation Jump to search

Diff selection: Mark the radio buttons of the revisions to compare and hit enter or the button at the bottom.
Legend: (cur) = difference with latest revision, (prev) = difference with preceding revision, m = minor edit.

20 September 2025

  • curprev 16:0516:05, 20 September 2025 Ryan talk contribs 2,493 bytes +2,493 Created page with "<span id="what-is-a-companion-in-kotlin"></span> == 1. What is a <code>companion</code> in Kotlin? == In Kotlin, you don’t have '''static methods or static variables''' like in Java. Instead, you use a '''<code>companion object</code>'''. A <code>companion object</code> is like a special object inside a class that is shared by all instances of that class. It acts a bit like <code>static</code> in Java. ----- <span id="syntax-of-companion-object"></span> == 2. Synt..."