Where does 'Hello World' get store; heap or stack ...
# getting-started
h
Where does 'Hello World' get store; heap or stack memory in the following code snippet :
😶 5
e
This is not Kotlin.
i
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
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.
This should be the case for all strings that are in the source file
e
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