KOTLIN / CATATAN</>↗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 / CATATAN</>↗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 […]
KOTLIN / CATATAN</>↗Kotlin21 Jun 2026
Object expressions vs. object declarations in Kotlin Kotlin has two closely related features: Object expressions: create an anonymous object immediately. Object declarations: create a named singleton object. They both use the object keyword, but they are used for different purposes. 1. Object expressions Use an object expression when you need a one-off object, often to […]
KOTLIN / CATATAN</>↗Kotlin21 Jun 2026
In Kotlin, a companion object is an object declared inside a class that can hold members callable on the class itself, giving you static-like behavior. Kotlin does not have Java-style static members directly. Instead, you usually use companion object. Basic example class User(val name: String) { companion object { const val DEFAULT_NAME = "Guest" fun […]
KOTLIN / CATATAN</>↗Kotlin21 Jun 2026
In Kotlin, classes can be declared inside other classes in two main ways: Nested classes — default behavior Inner classes — declared with the inner keyword Nested classes A class declared inside another class is nested by default. class Outer { class Nested { fun message(): String { return "Hello from Nested" } } } […]
KOTLIN / CATATAN</>↗Kotlin21 Jun 2026
In Kotlin, an abstract class is a class that cannot be instantiated directly. It is meant to be subclassed. An abstract method is a method declared without an implementation. Subclasses must override it. Basic example abstract class Animal { abstract fun makeSound() fun sleep() { println("Sleeping…") } } class Dog : Animal() { override fun […]