KOTLIN / NOTES</>↗Kotlin21 Jun 2026
In Kotlin, type aliases let you give a shorter, more meaningful name to an existing type. They are especially useful when your code has deeply nested generics, function types, or repeated complex class structures. A type alias does not create a new type. It only creates an alternative name for an existing type. Basic syntax […]
KOTLIN / NOTES</>↗Kotlin21 Jun 2026
In Kotlin, this, super, and @ labels are used to disambiguate which receiver or superclass member you mean, especially in nested scopes, inheritance, and inner classes. 1. this: refer to the current receiver Inside a class, this refers to the current instance of that class. class User(val name: String) { fun printName() { println(this.name) } […]
KOTLIN / NOTES</>↗Kotlin21 Jun 2026
In Kotlin, the by keyword is used for delegation. It lets one object delegate behavior to another object instead of implementing everything manually. There are two common forms: Interface/class delegation Property delegation 1. Interface delegation If a class implements an interface, it can delegate the implementation of that interface to another object using by. Example […]
KOTLIN / NOTES</>↗Kotlin21 Jun 2026
In Kotlin, properties can have custom getters and setters by defining get() and/or set(value) directly under the property. var propertyName: Type = initialValue get() { return field } set(value) { field = value } field is the backing field automatically generated by Kotlin when needed. Custom getter class Person( val firstName: String, val lastName: String […]
KOTLIN / NOTES</>↗Kotlin21 Jun 2026
In Kotlin, sealed classes (and sealed interfaces) let you model a closed, type-safe hierarchy: a fixed set of known subtypes. This is especially useful for things like UI state, results, commands, events, and domain-specific alternatives. Basic idea A sealed class restricts which classes can inherit from it. sealed class Result data class Success(val data: String) […]
KOTLIN / NOTES</>↗Kotlin21 Jun 2026
In Kotlin, enum class is used for a fixed set of constants. Enums can have: simple constants constructor parameters / associated data properties functions overridden behavior per constant companion object utilities implemented interfaces Basic enum enum class Direction { NORTH, SOUTH, EAST, WEST } Usage: val direction = Direction.NORTH when (direction) { Direction.NORTH -> println("Going […]