Java == for String objects ceased to work?

前端 未结 11 1208
情深已故
情深已故 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:50

    The JVM may optimize the String usage so that there is only one instance of the "equal" String in memory. In this case also the == operator will return true. But don't count on it, though.

提交回复
热议问题