Java String s = "a"+"b"+"c"; create object

1. Java String s = "a"+"b"+"c"; created several objects

        4 objects are created.

        Explanation: In the above code, the strings "a", "b", and "c" are all string literals, and they are all constants, so the compiler will combine them into one string constant "abc" at compile time .

        So, at runtime, 4 objects are actually created: the strings "a", "b", "c" in the constant pool and a new string object "abc".

unfinished, to be continued 

 

Guess you like

Origin blog.csdn.net/weixin_52255395/article/details/131640370