Java == for String objects ceased to work?

前端 未结 11 1210
情深已故
情深已故 2021-01-02 04:13
  public class Comparison {
        public static void main(String[] args) {
            String s = \"prova\";
            String s2 = \"prova\";
            System.         


        
11条回答
  •  时光取名叫无心
    2021-01-02 04:44

    String s = "prova";
    String s2 = "prova";
    

    s and s2 are literal strings which are pointing the same object in String Pool of JVM, so that the comparison returns true.

提交回复
热议问题