Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Effective Java ѧϰ±Ê¼Ç(8)

µ±ÖØÔØequals·½·¨Ê±,×ñÑ­¹ßÀý. equals²»ÊÇÿ¸öÀ඼±ØÐëÖØÔØ,µ±ÒÔϼ¸¸öÌõ¼þÂú×ã,¿ÉÒÔ²»ÖØÔØequals. 1. ÀàµÄʵÀýÖ»ÓÐͬһ¸ö²Å±»ÅÐΪÏàµÈ. ÈçThreadÀà. 2. ²»ÓùØÐÄÁ½¸ö¶ÔÏóÊÇ·ñÂß¼­ÏàµÈµÄʱºò,»òÊÇ˵±È½Ï¶ÔÏóûÓÐÒâÒå. 3.¸¸ÀàÒѾ­ÖØÔØÁËequals,¶øÇÒ¸¸ÀàµÄequalsÒ²ÊÊÓÃÓÚ×ÓÀà,×ÓÀà¾Í²»ÓÃÖØÔØequals. 4.ÕâÊÇÒ»¸ö˽ÓÐÀà»òÊÇ°üÄÚ·ÃÎÊ,ÄãÈ·¶¨equals²»»á±»µ÷ÓÃ. ÄÇʲôʱºòʹÓÃequalsÄØ,µ±Á½¸ö¶ÔÏóÖ®¼äÓÐÂß¼­ÏàµÈµÄÒâÒåµÄʱºò,¶øÆ丸ÀಢûÓÐÖØÔØÊʺϵÄequalsµÄʱºò, »»¾ä»°Ëµ,Ò²¾ÍÊÇÊý¾ÝÀà. ÕâÖÖÀàÓбȽÏÖµµÄÐèÇó, ¶ø²»ÊǼòµ¥µÄÅжÏÊDz»ÊÇͬһ¸ö¶ÔÏó. È»¶ø,¶ÔʵÀý»¯½øÐпØÖƵÄÊý¾ÝÀàÐͶÔÏó,Èçsingleton,²»ÓÃÖØÔØequals. ÖØÔØҪעÒâÒÔϼ¸¸öÔ­Ôò: ·´Éä,¶Ô³Æ,´«µÝ,Ò»Ö ÁíÍâ,¶ÔÓÚnull,Ò»¶¨Òª·µ»Øfalse. ¸ßЧµÄequals¿ÉÒԲο¼ÒÔϼ¸µã. 1. ÓÃ==ÅжÏÊDz»ÊÇͬһ¸öʵÀý. 2. ʹÓÃinstanceofÅжÏÊDz»ÊÇͬһ¸öÀàÐÍ. 3.Ç¿ÖÆת»¯³ÉÕýÈ·µÄÀàÐÍ. 4.¶Ôÿ¸öÓбȽÏÒâÒåµÄ³ÉÔ±±äÁ¿¶¼×÷¼ì²é. 5.µ±ÄãдÍêÖ®ºó,ÒªÎÊ×Ô¼º,Õâ¸öº¯ÊýÊDz»ÊǶԳƵÄ,¿É´«µÝµÄ,Ò»ÖµÄ. дÍêequalsºó,ҪעÒâ: 1. ÔÚÖØÔØequalsºó,±ØÐëÒªÖØÔØhashCode. 2. ²»Äܼòµ¥µÄ±È½ÏÒ»¸öfieldÊDz»ÊÇÏàµÈ. Èç¶ÔFileÕâ¶ÔÀà,Èç¹ûÁ½¸ö¶ÔÏó´ò¿ªµÄÊÇÏàͬÄÚÈݵÄÎļþ,´Ëʱ²»Ó¦¸ÃÅжÏΪÏàͬ. 3.²»ÒªÓÃÁíÒ»¸öÀàÐÍÀ´´úÌæ²ÎÊýÖеÄObject,·ñÔòÕâ¾Í²»ÊÇÖØÔØ. ´íÎóÀý×Ó: public boolean equals(MyClass o) {
...
} ÔÚ±àÒëǰʹÓÃ@Override ¿ÉÒÔʹ±àÒëÆ÷ÔÚ²»ÕýÈ·µÄº¯ÊýÇ©Ãûʱ±¨´í.


Ïà¹ØÎĵµ£º

Java Application Ö±½Óͨ¹ýjndiÁ¬½ÓÊý¾Ý¿â

À´Ô´£ºhttp://www.ej38.com/showinfo/java-132636.html
ʹÓÃjar°ü:
 commons-pool-1.5.3.jar,tomcat-naming-common.jar,commons-pool-1.5.3-bin.zip,commons-dbcp.jar
 ×¢Òâ:jdbc Çý¶¯ÒªÓëÊý¾Ý¿â¼æÈÝ.
 package test.comm;
import java.sql.Connection;
import java.sql.SQLException;
import java.u ......

JavaÖеÄÊý¾Ý±È½Ï£¨ÔÙ̸==ÓëequalsµÄÇø±ð£©


±¾×÷Æ·²ÉÓÃ֪ʶ¹²ÏíÊðÃû-·ÇÉÌÒµÐÔʹÓÃ-Ïàͬ·½Ê½¹²Ïí 2.5 Öйú´ó½Ðí¿ÉЭÒé½øÐÐÐí¿É¡£
JavaÖеıäÁ¿Óë¶ÔÏóÓÐÇø±ðÂð£¿
Òý×Ó£º±äÁ¿Óë¶ÔÏó
±äÁ¿ÊÇJavaÖÐ×î»ù±¾µÄ´æ´¢µ¥Ôª£¬Îª±äÁ¿¸³Öµ¿ÉÒÔʹÓø³Öµ±í´ïʽ¡£È磺
int i = 10;
¸Ã±í´ïʽµÄº¬ÒåÊǽ«Ò»¸ö×ÖÃæÁ¿£¨literal£©10¸³Öµ¸øÒ»¸öÀàÐÍΪintÐ͵ıäÁ¿£¬±äÁ¿ÃûΪi¡£ÕâÊÇÒ»¸öÎ ......

java ×¢Ê͹淶

×¢Ê͵ÄÔ­Ôò
1¡¢ ×¢ÊÍÐÎʽͳһ
ÔÚÕû¸öÓ¦ÓóÌÐòÖУ¬Ê¹ÓþßÓÐÒ»ÖµıêµãºÍ½á¹¹µÄÑùʽÀ´¹¹Ôì×¢ÊÍ¡£Èç¹ûÔÚÆäËûÏîÄ¿×é·¢ÏÖËûÃǵÄ×¢Ê͹淶ÓëÕâ·ÝÎĵµ²»Í¬£¬°´ÕÕËûÃǵĹ淶д´úÂ룬²»ÒªÊÔͼÔڼȳɵĹ淶ϵͳÖÐÒýÈëеĹ淶¡£
2¡¢ ×¢Ê͵ļò½à
ÄÚÈÝÒª¼òµ¥¡¢Ã÷ÁË¡¢º¬Òå׼ȷ£¬·ÀÖ¹×¢Ê͵ĶàÒåÐÔ£¬´íÎóµÄ×¢ÊͲ»µ«ÎÞÒæ·´¶øÓк¦¡£ ......

¶ÁÈ¡formÊý¾Ýʱ£¬java·´ÉäµÄÒ»µãÓ¦ÓÃ

package com.gis.biz;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.servlet.http. ......

Java»ùÓÚ¿ÉÀ©³äÊý×éµÄÏòÁ¿ÊµÏÖ(Ëã·¨Ô´Âë)

/* ¸ßÊÖÖ®×÷£¬±¾È˽÷ÒÔÊÕ²ØÕßÉí·ÝÄóö¹²Ïí¹©´ó¼Ò²Î¿¼! */
/*
 * ÏòÁ¿½Ó¿Ú
 */
package dsa;
public interface Vector {
//·µ»ØÏòÁ¿ÖÐÔªËØÊýÄ¿
 public int getSize();
//ÅжÏÏòÁ¿ÊÇ·ñΪ¿Õ
 public boolean isEmpty();
//È¡ÖÈΪrµÄÔªËØ
 public Object getAtRank(int r)
 throws ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ