Best practices/performance: mixing StringBuilder.append with String.concat

前端 未结 9 563
孤独总比滥情好
孤独总比滥情好 2020-12-07 08:23

I\'m trying to understand what the best practice is and why for concatenating string literals and variables for different cases. For instance, if I have code like this

9条回答
  •  余生分开走
    2020-12-07 08:47

    in byte code level there is not different and we are not compromising effeciancy there. In case of executing byte code level, it must go through non-inline operator overloading method for + by calling append. then in assembly language level (Java is written in C and C produces assemblies similar to assembly, there will be extra register call to store + method call in the stack and there will additional push. (in reality, cross-compiler might optimise + operator call, in that case making it no difference with efficiancy.)

    It is a good practice to have one way to increase the readability. :)

提交回复
热议问题