How to clone object in Kotlin?

For a data class, you can use the compiler-generated copy() method. Note that it will perform a shallow copy. To create a copy of a collection, use the toList() or toSet() methods, depending on the collection type you need. These methods always create a new copy of a collection; they also perform a shallow copy. … Read more

IntArray vs Array in Kotlin

Array<Int> is an Integer[] under the hood, while IntArray is an int[]. That’s it. This means that when you put an Int in an Array<Int>, it will always be boxed (specifically, with an Integer.valueOf() call). In the case of IntArray, no boxing will occur, because it translates to a Java primitive array. Other than the … Read more

Why does mutableStateOf without remember work sometimes?

It’s a feature of Compose about scoping and smart recomposition. You can check my detailed answer here. What really makes your whole Composable to recompose is Column having inline keyword. @Composable inline fun Column( modifier: Modifier = Modifier, verticalArrangement: Arrangement.Vertical = Arrangement.Top, horizontalAlignment: Alignment.Horizontal = Alignment.Start, content: @Composable ColumnScope.() -> Unit ) { val measurePolicy … Read more

Getters and Setters in Kotlin

Getters and setters are auto-generated in Kotlin. If you write: val isEmpty: Boolean It is equal to the following Java code: private final Boolean isEmpty; public Boolean isEmpty() { return isEmpty; } In your case the private access modifier is redundant – isEmpty is private by default and can be accessed only by a getter. … Read more

how to run compiled class file in Kotlin?

Knowing the Name of Your Main Class Currently (Kotlin since M14 including up to 1.0 betas), to run a Kotlin class you are actually running a special class that is created at the file level that hold your main() and other functions that are top-level (outside of a class or interface). So if your code … Read more