国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

== 和 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)