String s1 == String s2 (true) but FieldOffset is different

后端 未结 4 1150
生来不讨喜
生来不讨喜 2021-02-08 13:47

As I am studying java, I have learned that the proper way to compare 2 Strings is to use equals and not \"==\". This line

static String s1 = \"a\";
static String s2          


        
4条回答
  •  不知归路
    2021-02-08 14:39

    In the Code above you are not comparing the addresses of the strings, but their "location of a given field in the storage allocation", i.e. the location of the variables holding a reference to (the same) string.

提交回复
热议问题