Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created December 17, 2021 13:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Immutability | High performance with idiomatic Kotlin
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