国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

== 和 equal 的區(qū)別

2018-07-03 14:50 更新
  • == 比較引用的地址
  • equel 比較引用的內(nèi)容 (Object 類本身除外)

String obj1 = new String("xyz");
String obj2 = new String("xyz");


// If String obj2 = obj1, the output will be true


if(obj1 == obj2)
    System.out.printlln("obj1==obj2 is TRUE");
else
    System.out.println("obj1==obj2 is FALSE");


// It will print obj1==obj2 is False
// If String obj2 = obj1, the output will be true

默認(rèn)的, equals() 方法實(shí)際上和 “==” 在 object 類里是一樣的. 但是這個(gè)方法在每一個(gè)子類里都會(huì)被覆寫用來(lái)比較引用的內(nèi)容 (因?yàn)槊總€(gè)類都繼承了 object 類并覆寫了這個(gè)方法)

String obj1 = new String("xyz");
String obj2 = new String("xyz");


if(obj1.equals(obj2))
   System.out.printlln("obj1==obj2 is TRUE");
else
  System.out.println("obj1==obj2 is FALSE");


 Resultat: obj1==obj2 is TRUE
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)