4 月 18 2010
C# 的 ==、Equals 與 JAVA 的 ==、equals
剛感到好奇,各在 C# 與 JAVA 寫測試程式。
- C#:
Object myObj1 = 1; Object myObj2 = myObj1; Object myObj3 = 1; Console.WriteLine("myObj2.Equals(myObj1) = " + myObj2.Equals(myObj1)); Console.WriteLine("myObj3.Equals(myObj1) = " + myObj3.Equals(myObj1)); Console.WriteLine("(myObj2 == myObj1) = " + (myObj2 == myObj1)); Console.WriteLine("(myObj3 == myObj1) = " + (myObj3 == myObj1));
結果:
myObj2.Equals(myObj1) = True myObj3.Equals(myObj1) = True (myObj2 == myObj1) = True (myObj3 == myObj1) = False
- JAVA:
Object myObj1 = 1; Object myObj2 = myObj1; Object myObj3 = 1; System.out.println("myObj2.equals(myObj1) = " + myObj2.equals(myObj1)); System.out.println("myObj3.equals(myObj1) = " + myObj3.equals(myObj1)); System.out.println("(myObj2 == myObj1) = " + (myObj2 == myObj1)); System.out.println("(myObj3 == myObj1) = " + (myObj3 == myObj1));
結果:
myObj2.equals(myObj1) = true myObj3.equals(myObj1) = true (myObj2 == myObj1) = true (myObj3 == myObj1) = true
Tweets that mention Joe Horn 的啟示錄 » C# 的 ==、Equals 與 JAVA 的 ==、equals -- Topsy.com
2010-04-18 @ 18:33
[…] This post was mentioned on Twitter by 100大中文優質部落格, Joe Horn. Joe Horn said: shares http://tinyurl.com/y2jjmvy (C# 的 ==、Equals 與 JAVA 的 ==、equals) http://plurk.com/p/4qivpj […]