KOTLIN / CATATAN</>↗Kotlin03 Jun 2025
In Kotlin, you can use return, break, and continue inside loops to control the flow. Here’s a detailed explanation and examples for each: 1. Using return The return statement is used to terminate the execution of an enclosing function or lambda expression, and optionally return a value from it. If used inside a loop, it […]
KOTLIN / CATATAN</>↗Kotlin03 Jun 2025
In Kotlin, you can use ranges and step values in for loops to iterate over a sequence of numbers or characters. Here’s a detailed guide: 1. Ranges in Kotlin A range is defined using the .. operator. For example: for (i in 1..5) { println(i) } Output: 1 2 3 4 5 The loop iterates […]
KOTLIN / CATATAN</>↗Kotlin02 Jun 2025
Destructuring declarations in Kotlin simplify the process of unpacking values from objects, data classes, maps, arrays, or collections into individual variables. This is particularly useful when working with complex objects or collections. Below is an explanation of how to use destructuring declarations in different scenarios. 1. Data Classes Destructuring declarations work seamlessly with data classes. […]
KOTLIN / CATATAN</>↗Kotlin02 Jun 2025
In Kotlin, scope functions such as let, also, and run can be used effectively for handling null safety. These functions allow you to operate on nullable objects and execute a block of code only if the object is not null. Here’s how these scope functions can be applied for null safety: 1. let The let […]
KOTLIN / CATATAN</>↗Kotlin01 Jun 2025
In Kotlin, the !! operator is called the not-null assertion operator. It is used to tell the compiler that a null value will never be encountered for a given variable. If Kotlin encounters a null during runtime while using !!, it will throw a NullPointerException (NPE). While using !! can be convenient in some cases, […]
KOTLIN / CATATAN</>↗Kotlin01 Jun 2025
In Kotlin, smart casts are a feature that allows the compiler to automatically cast an object to a target type within a certain scope if it determines that the cast is safe. Smart casts are most commonly used in control flow statements, such as if, when, and loops. Here’s how you can use smart casts […]