Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created December 17, 2021 13:31
Show Gist options
  • Save magdamiu/bc14427a6b35c57dc59ba7841efe775c to your computer and use it in GitHub Desktop.
Save magdamiu/bc14427a6b35c57dc59ba7841efe775c to your computer and use it in GitHub Desktop.
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