¡¾×ª¡¿ÈçºÎÔÚJavaÖбÜÃâequals·½·¨µÄÒþ²ØÏÝÚå
ÒëÕß×¢ :Äã¿ÉÄÜ»á¾õµÃJavaºÜ¼òµ¥£¬ObjectµÄequalsʵÏÖÒ²»á·Ç³£¼òµ¥£¬µ«ÊÇÊÂʵ²¢²»ÊÇÄãÏëÏóµÄÕâÑù£¬ÄÍÐĵĶÁÍê±¾ÎÄ£¬Äã»á·¢ÏÖÄã¶ÔJavaÁ˽âµÄÊÇÈç´ËµÄÉÙ¡£Èç¹ûÕâƪÎÄÕÂÊÇÒ»·ÝJava³ÌÐòÔ±µÄÈëÖ°±ÊÊÔ£¬ÄÇô²»ÖªµÀÓжàÉÙÈË»áµôÂäµ½ÕâÑùµÄÏÝÚåÖС£ÔÎÄת×Ôhttp://www.artima.com/lejava/articles/equality.html Èýλ×÷Õ߶¼ÊDz»Í¬ÁìÓòµÄ´óÄã¬ÓÐÐËȤµÄ¶ÁÕß¿ÉÒÔ´ÓÉÏÃæÕâ¸öÁ¬½ÓÖ±½ÓÈ¥ÔĶÁÔÎÄ¡£
ÕªÒª
±¾ÎÄÃèÊöÖØÔØequals·½·¨µÄ¼¼Êõ£¬ÕâÖÖ¼¼Êõ¼´Ê¹ÊǾßÏÖÀàµÄ×ÓÀàÔö¼ÓÁË×Ö¶ÎÒ²Äܱ£Ö¤equalÓïÒåµÄÕýÈ·ÐÔ¡£
ÔÚ¡¶Effective Java¡·µÄµÚ8ÏîÖУ¬Josh BlochÃèÊöÁ˵±¼Ì³ÐÀà×÷ΪÃæÏò¶ÔÏóÓïÑÔÖеĵȼ۹ØϵµÄ»ù´¡ÎÊÌ⣬Ҫ±£Ö¤ÅÉÉúÀàµÄequalÕýÈ·ÐÔÓïÒåËù»áÃæ¶ÔµÄÀ§ÄÑ¡£BlochÕâÑùдµ½£º
³ý·ÇÄãÍü¼ÇÁËÃæÏò¶ÔÏó³éÏóµÄºÃ´¦£¬·ñÔòÔÚµ±Äã¼Ì³ÐÒ»¸öÐÂÀà»òÔÚÀàÖÐÔö¼ÓÁËÒ»¸öÖµ×é¼þʱÄãÎÞ·¨Í¬Ê±±£Ö¤equalµÄÓïÒåÒÀÈ»ÕýÈ·
ÔÚ¡¶Programming in Scala¡·ÖеĵÚ28ÕÂÑÝʾÁËÒ»ÖÖ·½·¨£¬ÕâÖÖ·½·¨ÔÊÐí¼´Ê¹¼Ì³ÐÁËÐÂÀ࣬Ôö¼ÓÁËеÄÖµ×é¼þ£¬equalµÄÓïÒåÈÔÈ»Äܵõ½±£Ö¤¡£ËäÈ»ÔÚÕâ±¾ÊéÖÐÕâÏî¼¼ÊõÊÇÔÚʹÓÃScalaÀà»·¾³ÖУ¬µ«ÊÇÕâÏî¼¼ÊõͬÑù¿ÉÒÔÓ¦ÓÃÓÚJava¶¨ÒåµÄÀàÖС£ÔÚ±¾ÎÄÖеÄÃèÊöÀ´×ÔÓÚProgramming in ScalaÖеÄÎÄ×ÖÃèÊö£¬µ«ÊÇ´úÂë±»ÎÒ´Óscala·Òë³ÉÁËJava
³£¼ûµÄµÈ¼Û·½·¨ÏÝÚå
java.lang.Object ÀඨÒåÁËequalsÕâ¸ö·½·¨£¬ËüµÄ×ÓÀà¿ÉÒÔͨ¹ýÖØÔØÀ´¸²¸ÇËü¡£²»ÐÒµÄÊÇ£¬ÔÚÃæÏò¶ÔÏóÖÐд³öÕýÈ·µÄequals·½·¨ÊǷdz£À§Äѵġ£ÊÂʵÉÏ£¬ÔÚÑо¿ÁË´óÁ¿µÄJava´úÂëºó£¬2007 paperµÄ×÷ÕߵóöÁËÈçϵÄÒ»¸ö½áÂÛ£º
¼¸ºõËùÓеÄequals·½·¨µÄʵÏÖ¶¼ÊÇ´íÎóµÄ£¡
Õâ¸öÎÊÌâÊÇÒòΪµÈ¼ÛÊǺͺܶàÆäËûµÄÊÂÎïÏà¹ØÁª¡£ÀýÈçÆäÖÐÖ®Ò»£¬Ò»¸öµÄÀàÐÍCµÄ´íÎóµÈ¼Û·½·¨¿ÉÄÜÒâζ×ÅÄãÎÞ·¨½«Õâ¸öÀàÐÍCµÄ¶ÔÏó¿ÉÐÅÀµµÄ·ÅÈëµ½ÈÝÆ÷ÖС£±ÈÈç˵£¬ÄãÓÐÁ½¸öÔªËØelem1ºÍelem2ËûÃǶ¼ÊÇÀàÐÍCµÄ¶ÔÏ󣬲¢ÇÒËûÃÇÊÇÏàµÈ£¬¼´elem1.equals(elm2)·µ»Øture¡£µ«ÊÇ£¬Ö»ÒªÕâ¸öequals·½·¨ÊÇ´íÎóµÄʵÏÖ£¬ÄÇôÄã¾ÍÓпÉÄܻῴ¼ûÈçϵÄһЩÐÐΪ£º
Set hashSet = new java.util.HashSet();
hashSet.add(elem1);
hashSet.contains(elem2); // returns false!
µ±equalsÖØÔØʱ£¬ÕâÀïÓÐ4¸ö»áÒý·¢equalsÐÐΪ²»Ò»Öµij£¼ûÏÝÚ壺
¶¨ÒåÁË´íÎóµÄequals·½·¨Ç©Ãû(signature) Defining equals with the wrong signature.
ÖØÔØÁËequalsµÄµ«Ã»ÓÐͬʱÖØÔØhashCodeµÄ·½·¨¡£ Changing equals without also changing hashCode.
½¨Á¢ÔÚ»á±ä»¯×ÖÓòÉϵÄequals¶¨Òå¡£ Defining equals
Ïà¹ØÎĵµ£º
import java.io.*;
import java.lang.String;
public class Switchover {
public static String[] strChi = {"Áã","Ò¼","·¡","Èþ","ËÁ","Îé","½","Æâ","°Æ","¾Á"};
public static String[] strUnits = {"","","Ê°","°Û","Ǫ","Íò","Ê°","°Û","Ǫ","ÒÚ","Ê°","°Û","Ǫ","Õ×","Ê°","°Û","Ǫ","½Ç","·Ö"};
//ÑéÖ¤Êä ......
JDO ¸ÅÊö
¡¡¡¡³¤¾ÃÒÔÀ´£¬Java Ó¦ÓóÌÐòºÍ³Ö¾ÃÊý¾Ý¹ÜÀíÖ®¼äµÄ¹ØϵһֱÊDz»ÈÝÒ×´¦ÀíµÄ¡£Ðí¶à³Ö¾ÃÐÔ»úÖÆÒÔ¹ØϵµÄ·½·¨¶ø²»ÊÇÃæÏò¶ÔÏó·½·¨´æ´¢Êý¾Ý¡£¼´£¬Êý¾Ý´æ´¢ÔÚÓÉ°üº¬×ֶεļǼ×é³ÉµÄ±íÖУ¬¶ø²»ÊǴ洢Ϊ×Ô°üº¬¶ÔÏó(ÕâЩ¶ÔÏóÓµÓÐÄÚ²¿Êý¾ÝºÍ¶ÔÆäËü¶ÔÏóµÄÒýÓ㬶øÆäËü¶ÔÏóÒ²ÓµÓÐÄÚ²¿Êý¾ÝºÍÒýÓÃ)¡£½«ÃæÏò¶ÔÏóµÄ±íʾת»»³ ......
ÕâÊÇÒ»¸ö¼òµ¥µÄ¶ÁÈ¡ÎļþµÄ´úÂ룬²¢ÊÔ×ŶÁÈ¡Ò»¸ölogÎļþ£¬ÔÙÊä³ö¡£
import java.io.*;
public class FileToString {
public static String readFile(String fileName) {
String output = "";
File file = new File(fileName);
if(file.exists()){
......
Ö÷ÒªÊÇ×ö¸÷µØÒøÐеÄÍâΧϵͳ£¬ÀýÈçµç×Ó»ãƱ¡¢·´Ï´Ç®ÏµÍ³µÈ£¬ÓÐÐËȤµÄ¿ÉÒÔ¼ÓÎÒQQ£¨429177125£©¾ßÌåÁÄ£¬ÃæÊԵصãÔÚ±±¾©Êк£µíÇøκ¹«´å¡£
¾ßÌåÈçÏ£º
Java¹¤×÷¾Ñ飬2-3Äê
ÈíÐÔÒªÇó£º ÒÔϹ¤×÷¾ÑéÖ®Ò»ÕßÓÅÏÈ¡£1¡¢ ÓÐÒøÐй¤×÷¾ ......
ÔÚͨ¶ÁjdkÔ´´úÂëµÄʱºò·¢ÏÖÐí¶àjava·½·¨Ç°¶¼ÓÐnative¹Ø¼ü×ÖÐÞÊΣ¬×îºóµÃÖªnativeÊÇÓëC++ÁªºÏ¿ª·¢µÄʱºòÓõģ¬java×Ô¼º¿ª·¢²»Óá£
ʹÓÃnative¹Ø¼ü×Ö˵Ã÷Õâ¸ö·½·¨ÊÇÔÉúº¯Êý£¬Ò²¾ÍÊÇÕâ¸ö·½·¨ÊÇÓÃC/C++ÓïÑÔʵÏֵģ¬²¢ÇÒ±»±àÒë³ÉÁËDLL£¬ÓÉjavaÈ¥µ÷Óá£ÕâЩº¯Êý ......