Why String s1 = "hello" String s2 = new String ( "hello") s1 == s2 is flase

    String s2 = new String ( "hello") if the constant pool to create three objects without creating a hello hello objects in the heap and then create a new String object has a data type of the stack of variable String s2

    s2 address is saved heap to create an object address

     String s1 = "hello" hello see whether the target string constant pool no return address value is created if the object is returned directly address value

 

Guess you like

Origin www.cnblogs.com/zhongmeilin/p/11616399.html