Effective Java ѧϰ±Ê¼Ç (11)
CloneÕâ¸ö·½·¨ºÜ¼¦Àߣ¬ÔÒòÊÇÒòΪËüÊÇÊܱ£»¤µÄ(protected)£¬Æä¶þCloneÕâ¸ö·½·¨ÊÇ¿ÉÑ¡µÄ£¬¼´ÓпÉÄÜÀàûÓÐÌṩÕâ¸ö·½·¨¡£
cloneûÓе÷Óù¹Ô캯Êý£¬¶øÇÒÈç¹û¸¸ÀàûÓÐʵÏÖcloneµÄ»°£¬×ÓÀàÓÀÔ¶Ò²²»¿ÉÄÜÕýȷʵÏÖclone.
×ÜÖ®£¬cloneÊǸöºÜÍ·Í´µÄº¯Êý£¬Èç¹ûÒªÕýȷʵÏÖ£¬±ØÐ뿼Âǵ½É±´µÄÇé¿ö£¬·ñÔò±»¿Ë¡³öÀ´µÄ¶ÔÏó¾Í²»ÊǶÀÁ¢µÄ£¬È磬Ҫдһ¸ö¶ÑÕ»ÀàµÄ¿Ë¡º¯Êý£¬ÕýÈ·µÄʵÏÖ·½·¨ÊÇ£º
@Override public Stack clone() {
try {
Stack result = (Stack) super.clone();
result.elements = elements.clone();
return result;
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
ҪעÒâ¶ÔÓÚfinal×ֶβ»ÄÜÕý³£¹¤×÷£¬clone½á¹¹Óë¿É±ä¶ÔÏóµÄfinal×Ö¶ÎÊDz»¼æÈݵġ£
¶ÔÓÚÁÐÉ¢Êý×飬½ö½öµÝ¹éµ÷ÓõÄclone·½·¨»¹²»¹»£¬¿´ÊéÖÐÕýÈ·µÄ×ö·¨£º
public class HashTable implements Cloneable {
private Entry[] buckets = ...;
private static class Entry {
final Object key;
Ïà¹ØÎĵµ£º
Oracle and Sun
http://www.oracle.com/events/productstrategy/index.html
Oracle + Sun: Java Strategy
http://oracle.com.edgesuite.net/ivt/4000/8104/9236/12630/lobby_external_flash_clean_480x360/default.htm
Oracle + Sun: Java Strategy
......
ÿÌì»ù´¡£¨1£©£¬´®Æ¥ÅäÖ®Brute-ForceËã·¨£¬×î¼òµ¥µÄ±éÀúËã·¨¡£ÁíÍâÓÐKMPËã·¨£¬ÊǶԴËËã·¨µÄ¸Ä½ø£¬±ÜÃâÿ´Î±È½Ï¶¼»Ø»ØÍË¡£
package ibees.sample;
/**
* ×Ö·û´®Æ¥ÅäģʽËã·¨Brute-ForceËã·¨£¬´ËË㷨ÿ´Î±È½Ï¶¼»á»ØÍË
* @author hhzxj2008
* */
public class StringMatch {
/**
* Ï൱ÓÚjava.lang.StringµÄi ......
×öB/SµÄÆóÒµ¼¶Ó¦Ó㬿ÉÄÜ»áÓöµ½ÕâÑùÒ»ÖÖÇé¿ö£¬¿Í»§µÄÎĵµ£¨wordµÈ£©±£´æÔÚÒ»¸öĿ¼Ï£¬ÐèҪͨ¹ýµÇ¼²ÅÄÜ¿´µ½£¬µ«ÊÇ
ÕâЩÓÖ¶¼ÊǾ²Ì¬µØÖ·£¬ËùÒÔÄÜÖ±½ÓÊäÈëµØÖ·¾Í¿ÉÒÔ·ÃÎʵ½Îĵµ¡£Õâʱ¾ÍÐèÒªÓõ½Filter¹ýÂËÆ÷ÁË¡£
Servlet
APIµÄ2.3°æ±¾µÄÒ»¸öй¦ÄܾÍÊÇÄܹ»ÎªservletºÍJSPÒ³Ãæ¶¨Òå¹ýÂËÆ÷¡£¹ýÂËÆ÷ÌṩÁËijЩÔçÆÚ·þÎñÆ÷Ë ......
1. µ±Ä³¸öÀàÖеÄij¸ö·½·¨Öеľֲ¿±äÁ¿µÄÃû×ÖÓë¸ÃÀàÖеÄÈ«¾Ö±äÁ¿µÄÃû×ÖÏàͬʱ ¸ÃÈ«¾Ö±äÁ¿½«±»Òþ²Ø£»´Ëʱ Èç¹ûÏëÔڸ÷½·¨ÖÐʹÓÃÈ«¾Ö
±äÁ¿ ±ØÐëʹÓùؼü×Ö£¨this.È«¾Ö±äÁ¿Ãû£©
2. µ±this¹Ø¼ü×Ö³öÏÖÔÚÀàµÄʵÀý·½·¨ÖÐʱ£¬´ú±íÕýÔÚµ÷Óø÷½·¨µÄµ±Ç°¶ÔÏó
3.  ......
ʹÓÃJava²Ù×÷Îı¾ÎļþµÄ·½·¨Ïê½â
ÕªÒª: ×î³õjavaÊDz»Ö§³Ö¶ÔÎı¾ÎļþµÄ´¦ÀíµÄ£¬ÎªÁËÃÖ²¹Õâ¸öȱº¶¶øÒýÈëÁËReaderºÍWriterÁ½¸öÀà
×î³õjavaÊDz»Ö§³Ö¶ÔÎı¾ÎļþµÄ´¦ÀíµÄ£¬ÎªÁËÃÖ²¹Õâ¸öȱº¶¶øÒýÈëÁËReaderºÍWriterÁ½¸öÀ࣬ÕâÁ½¸öÀà¶¼ÊdzéÏóÀ࣬WriterÖÐ write(char[] ch,int off,int
length)£¬flush()ºÍclose()·½·¨Îª³éÏó·½· ......