Noob question about how the compiler handles strings.

Noob question about how the compiler handles strings.

I’ve been writing an API server in Kotlin (targeting the JVM) for a project of mine having written Java for a fair while. I have two questions about the low-level behaviour of strings:

  • In Java, strings are immutable so you have to use a StringBuilder if you’re concatenating strings in a loop to avoid wasting memory. I’ve been doing this out of habit, but is it actually necessary in Kotlin or will the compiler perform this optimisation itself?

  • How do multi-line strings actually work under the bonnet? Are they any more expensive than ordinary strings?

Cheers in advance!

submitted by /u/AdmiralGinge
[link] [comments]