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