KOTLIN / CATATAN</>↗Kotlin26 Jun 2026
In Kotlin, the Elvis operator ?: provides a fallback value when the expression on its left is null. val result = nullableValue ?: defaultValue If nullableValue is not null, result gets that value. If nullableValue is null, result gets defaultValue. Example: val name: String? = null val displayName = name ?: "Guest" println(displayName) // Guest […]
KOTLIN / CATATAN</>↗Kotlin26 Jun 2026
In Kotlin, the safe call operator ?. lets you access a property or call a function only if the value is not null. If the value is null, the expression simply returns null instead of throwing a NullPointerException. val name: String? = null val length = name?.length println(length) // null Here, name is nullable because […]
KOTLIN / CATATAN</>↗Kotlin26 Jun 2026
In Kotlin, you declare a nullable variable by adding ? after the type. var name: String? = null This means name can hold either a String value or null. Examples: var age: Int? = null age = 25 val email: String? = "user@example.com" val phone: String? = null Without ?, Kotlin does not allow null: […]
KOTLIN / CATATAN</>↗Kotlin26 Jun 2026
Kotlin handles null safety through its type system: a normal type like String cannot be null, while a nullable type like String? can be null. 1. Use nullable types when a value may be null val name: String = "Alice" // Cannot be null val nickname: String? = null // Can be null If a […]
KOTLIN / CATATAN</>↗Kotlin26 Jun 2026
You typically combine Kotlin collections, coroutines, and Flow by using: collections for in-memory data coroutines for concurrency / async work Flow for asynchronous streams of values Basic idea If you have a collection: val ids = listOf(1, 2, 3, 4, 5) You can turn it into a Flow: val idFlow = ids.asFlow() Then process each […]
KOTLIN / CATATAN</>↗Kotlin25 Jun 2026
In Kotlin, inline functions and reified type parameters are especially useful in collection processing when you want to write generic, type-safe utilities that still need access to the actual runtime type. Normally, generic type information is erased at runtime, but reified type parameters in inline functions let you do checks like is T, as T, […]