Created
December 17, 2021 13:31
-
-
Save magdamiu/bc14427a6b35c57dc59ba7841efe775c to your computer and use it in GitHub Desktop.
Immutability | High performance with idiomatic Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ValueHolder<V> { | |
val value: V | |
} | |
class IntHolder : ValueHolder<Int> { | |
override val value: Int | |
get() = Random().nextInt() | |
} | |
fun main() { | |
val sample = IntHolder() | |
println(sample.value) //260078462 | |
println(sample.value) //1657381068 | |
} | |
// immutability by default | |
data class ImmutableKey(val name: String? = null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment