Kotlin object and companion object (with Examples)
Kotlin object and companion object: singletons, object expressions, companion objects for factory functions and constants, and @JvmStatic.
Kotlin tutorials for beginners: functions, classes and objects, interfaces, collections and small programs you can run in Android Studio.
Free course · Beginner friendly
From your first program to coroutines. Each lesson builds on the one before, so follow them in order.
Kotlin object and companion object: singletons, object expressions, companion objects for factory functions and constants, and @JvmStatic.
Kotlin sealed classes and sealed interfaces: restricted hierarchies, exhaustive when, modeling UI state and results, and sealed class vs enum.
Kotlin enum classes explained: constants, properties and functions, entries, valueOf, name and ordinal, enums with when, and enums with interfaces.
Kotlin data classes: what they generate (equals, hashCode, toString, copy), destructuring, rules and limits, and data class vs regular class.
Kotlin abstract classes: abstract functions and properties, shared code and state, constructors, and when to use an abstract class vs an interface.
Kotlin visibility modifiers explained: public, private, protected and internal for classes, members and top-level code, with examples and when to use each.
Kotlin inheritance explained: why classes are final by default, open and override, calling super, overriding properties and polymorphism.
Kotlin constructors explained: primary constructors with val and var, default values, init blocks, secondary constructors and require checks.
Kotlin collection functions with examples: map, filter, forEach, any/all/none, find, sumOf, sortedBy, groupBy, partition, flatMap, zip, fold and reduce.
Kotlin Map and MutableMap: mapOf with to, reading values safely, getOrDefault, adding and updating entries, looping, filtering and counting.