Where does 'Hello World' get store; heap or stack memory in the following code snippet :
😶 5
e
ephemient
08/26/2022, 5:27 PM
This is not Kotlin.
i
ilya.gorbunov
08/26/2022, 6:43 PM
I would not be so strict about that.
If I ran Java-to-Kotlin conversion on the snippet, would the same question be relevant for Kotlin? 😉
Where does 'Hello World' get store; heap or stack memory in the following code snippet :
Copy code
fun main() {
println("Hello World")
}
K 1
l
Landry Norris
08/26/2022, 7:04 PM
This will vary by Kotlin platform, but for JVM, the String "Hello World" gets stored in the class file and stored with the class information by the vm. When System.out accesses it, it uses an index into the class information.
Landry Norris
08/26/2022, 7:04 PM
This should be the case for all strings that are in the source file
e
ephemient
08/27/2022, 12:56 AM
there's no guarantee of that - in fact, if your string is too long, the Kotlin compiler will split it up and perform concatenation at runtime, due to classfile constraints