String valueOf vs concatenation with empty string

后端 未结 10 1672
说谎
说谎 2020-11-27 05:05

I am working in Java code optimization. I\'m unclear about the difference between String.valueOf or the +\"\" sign:

int intVar = 1;         


        
10条回答
  •  执笔经年
    2020-11-27 05:39

    Concatenating Strings and other variables actually uses String.valueOf() (and StringBuilder) underneath, so the compiler will hopefully discard the empty String and produce the same bytecodes in both cases.

提交回复
热议问题