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;


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


Looks related to – constant folding doesn’t work with operator function calls in ordinary form.

1 Like