Last active
February 26, 2022 15:28
-
-
Save evilthreads669966/0376d1b63175116dbefc986733b4a77e to your computer and use it in GitHub Desktop.
value class with computed property. value classes may not have generic type parameters. nor can they have more than one "backed" property. If Bar is treated as an integer value at compile time, then how does it hold on to a reference to the computed property? Or better yet, how does a primitive value have a reference to the computed property?
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
@JvmInline | |
value class Bar(private val _foo: Int){ | |
val computed: Int | |
get() = _foo.toString().length | |
} | |
@Throws(AssertionError::class) | |
fun testBar(){ | |
val arg = 22 | |
val argLength = arg.toString().length | |
val bar = Bar(arg) | |
val length = bar.computed | |
assert(length == argLength) | |
assert(length > 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment