y
12/15/2025, 11:24 AMget() vals bloat the size of a class instance?CLOVIS
12/15/2025, 12:28 PMval foo: Int
is the exact same output binary than
val foo: Int
get() = field
which are both slightly bigger than
private val foo: Int
(because that one doesn't have a getter at all)CLOVIS
12/15/2025, 12:29 PMy
12/15/2025, 12:58 PMfield example above, that's what I expected. thanks.
what about something like this?
class Foo(val a: Int, val b: Int) {
val c: Int get() = a + b
}CLOVIS
12/15/2025, 2:55 PMclass Foo(val a: Int, val b: Int) {
fun getC(): Int = a + b
}CLOVIS
12/15/2025, 2:59 PMkotlin("jvm") projects)
• Tools → Kotlin → Show Kotlin bytecode
• Click on your Kotlin code
• Click on 'Decompile'
This will show you pseudo-Java code generated by your Kotlin codey
12/15/2025, 3:01 PMCLOVIS
12/15/2025, 3:02 PMKlitos Kyriacou
12/15/2025, 10:00 PMClass, of which there is only one instance (e.g. Foo::class) no matter how many instances of the class you create. So it's negligible.y
12/15/2025, 10:02 PMy
12/15/2025, 10:02 PM