String concatenation with plus

I was decompiling some approaches on string concatenation, like with constants and values etc., when I saw following code

val a = "Test " + 2
val b = "Test ".plus(2)

is decompiled in java side to

String h = "Test 2";
String i = "Test " + 2;

respectively.

Since plus is operator function, why does this happen ? Shouldn’t they produce exactly same output ?

Looks related to https://youtrack.jetbrains.com/issue/KT-30605 – constant folding doesn’t work with operator function calls in ordinary form.

1 Like