KOTLIN / CATATAN</>↗Kotlin21 Jun 2026
In Kotlin, the idiomatic way to implement the Singleton pattern is to use an object declaration. object AppConfig { val appName = "MyApp" fun printConfig() { println("App name: $appName") } } You use it directly by its name: fun main() { AppConfig.printConfig() println(AppConfig.appName) } Kotlin guarantees that an object declaration: has exactly one instance is […]
KOTLIN / CATATAN</>↗Kotlin21 Jun 2026
You can mix OOP and functional programming in Kotlin by using objects/classes to model state, identity, boundaries, and domain concepts, while using functions/lambdas to model behavior, transformation, policies, and workflows. Kotlin is especially good at this because it supports: Classes, interfaces, inheritance, encapsulation Data classes and sealed classes Lambdas and higher-order functions Immutability with val […]
KOTLIN / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 […]