ÉîÈëdz³öJava clone¼¼Êõ
¡¡ÕâÊÇclone¼¼Êõ½éÉܵĵÚһƪ¡£±¾ÆªÖ÷Òª½éÉܶÔÏóclone¼¼ÊõµÄ»ù±¾ÖªÊ¶¡£
Clone»ù±¾ÖªÊ¶´¢±¸
ÔÚJavaÀïÌáµ½clone¼¼Êõ£¬¾Í²»Äܲ»Ìájava.lang.Cloneable½Ó¿ÚºÍº¬ÓÐclone·½·¨µÄObjectÀà¡£ËùÓоßÓÐclone¹¦ÄܵÄÀà¶¼ÓÐÒ»¸öÌØÐÔ£¬ÄǾÍÊÇËüÖ±½Ó»ò¼ä½ÓµØÊµÏÖÁËCloneable½Ó¿Ú¡£·ñÔò£¬ÎÒÃÇÔÚ³¢ÊÔµ÷ÓÃclone£¨£©·½·¨Ê±£¬½«»á´¥·¢CloneNotSupportedExceptionÒì³£¡£ÏÂÃæÎÒÃÇͨ¹ý¶ÔObjectÀàµÄ²¿·ÖÔ´ÂëµÄ·ÖÎö£¬À´·¢ÏÖºÍÀí½âÕâÒ»ÌØÐÔ¡£Çë¿´JDKÖÐObject# clone()·½·¨µÄÔ´Â룺
/*
…………
* @return a clone of this instance.
* @exception? CloneNotSupportedException? if the object's class does not
*support the Cloneable interface. Subclasses
*that override the clone method can also
* throw this exception to indicate that an instance cannot
*be cloned.
* @see java.lang.Cloneable
*/
protected native Object clone() throws CloneNotSupportedException;
Õâ¶ÎÔ´ÂëµÄ@exception²¿·ÖµÄÃèÊöÄÚÈÝ֤ʵÁËÉÏÎĹØÓÚclone¶ÔÏóÌØÐÔÂ۶ϵÄÕýÈ·ÐÔ¡£ËüÃ÷È·Ö¸³ö¶ÔÏóÀà±ØÐëÖ§³ÖCloneable½Ó¿Ú£¬·ñÔò¼´Ê¹ÅÉÉúÀา¸ÇÁËObject#clone()·½·¨£¬Ò²Í¬Ñù»áÅ׳öCloneNotSupportedExceptionÕâ¸öÒì³£¡£¹ØÓÚ¸²¸Çclone()·½·¨£¬ºóÐøÎÄÕ½«»áÓÃרÃÅÆª·ù½øÐбȽÏÏêϸµÄ·ÖÎö.
ÔÚÉÏһƪÖУ¬½éÉÜÁËjavaÀïcloneµÄ»ù±¾ÖªÊ¶¡£±¾Æª½«×ÅÖØÃèÊöÈçºÎʵÏÖclone¡£
l cloneµÄʵÏÖ
1.ʵÏÖCloneable½Ó¿Ú
ͨ¹ýÉÏһƪµÄ½éÉÜ£¬ÎÒÃÇÖªµÀ£¬Ò»¸öÀàÈôÒª¾ß±¸clone¹¦ÄÜ£¬¾Í±ØÐëʵÏÖCloneable½Ó¿Ú¡£×öµ½ÕâÒ»²½£¬clone¹¦ÄÜÒѾ»ù±¾ÊµÏÖÁË¡£Clone¹¦ÄܶÔÎÒÃÇÀ´Ëµ£¬×îÖ÷ÒªµÄ»¹ÊÇÒªÄܹ»Ê¹ÓÃËü¡£ÄÇôÎÒÃÇÈçºÎ²ÅÄÜʹÓÃclone¹¦ÄÜÄØ£¿´ð°¸ÊǸ²¸ÇObject#clone()·½·¨¡£
2. ¸²¸ÇObject#clone()·½·¨
ΪʲôÐèÒª¸²¸ÇObject#clone()·½·¨£¿ÕâÀïµÃÔٴδÓjdkÔ´Âë˵Æð¡£JDKÖÐObject# clone()·½·¨µÄÔÐÍÊÇ£º
protected native Object clone() throws CloneNotSupportedException;
ÊÇ·ñ×¢Òâµ½£¬ÕâÀïclone()·½·¨ÐÞÊηûÊÇprotected£¬¶ø²»ÊÇpublic¡£ÕâÖÖ·ÃÎʵIJ»¿É¼ûÐÔʹµÃÎÒÃǶÔObject#clone()·½·¨²»¿É¼û¡£ÏàÐŶÁÕßÒÑÃ÷°×ΪʲôҪ¸²¸ÇObject#clone()·½·¨¡£¶øÇÒ£¬¸²¸ÇµÄ·½·¨µÄÐÞÊηû±ØÐëÊÇpublic£¬Èç¹û»¹±£ÁôΪprotected£¬¸²¸Ç½«±äµÃûÓÐʵ¼ÊÒâÒå¡£ÏÂÃæ¾ÙÒ»¸ö¾ßÓÐclone¹¦Äܵļòµ¥µÄÀý×Ó£º
/*
* ¾ßÓÐclone¹¦ÄܵÄÀàµÄÀý×Ó
*/
public class CloneableObjExampl
Ïà¹ØÎĵµ£º
ÔÚjavaÖе÷ÓÃ×Ô¼ºµÄc++´úÂëÊÇÒ»¼þ¼òµ¥µÄÊÂÇ飬ÒÔÏÂÀàΪÀý£º
class Prompt {
private native String getLine(String prompt);
public static void main(String args[]) {
Prompt p = new Prompt();
String input = p.getLine("Type a line: ");
&nbs ......
°ücommons-net-1.4.1.zip
import org.apache.commons.io.IOUtils;
import org.apache.commons.net.ftp.FTPClient;
import com.eduvideotv.util.Global;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileOutputStream;
/**
* Apache commons-net ÊÔÓ ......
ÏÂÃæÒÔ±àÒë /src/com/dream/io/ScannerTest.javaΪʾÀý£º
1¡¢ÓÃjavac±àÒë.javaÎļþʱ£¬½øÈësrcĿ¼ºó£¬ÊäÈë javac com/dream/io/ScannerTest.java£¬ »Ø³µ£¬¼´¿É±àÒëScannerTest.javaÎļþΪ.classÎļþ£»Ò²¿É£¬½øÈë /src/com/dream/io/ Ŀ¼ºó£¬ ÊäÈë javac ScannerTest.java£¬ »Ø³µ£¬Ò²¿É±àÒë ScannerTest.javaÎļþΪ .clas ......
1¡¢ public class HelloWorld {
public static void main(String args[]){
String s="daxiong";
System.out.println("Hello,World!"+"lu shenglong"+s);
char c[]={'s','w','q'};
&nb ......
·½·¨Ò»£º
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
·½·¨¶þ£º
Map map = n ......