ÉîÈë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
Ïà¹ØÎĵµ£º
native2ascii.exe ÊÇ Java µÄÒ»¸öÎļþתÂ빤¾ß£¬Êǽ«ÌØÊâ¸÷ÒìµÄÄÚÈÝ ×ªÎª ÓÃÖ¸¶¨µÄ±àÂë±ê×¼ÎÄÌåÐÎʽͳһµÄ±íÏÖ³öÀ´£¬Ëüͨ³£Î»ÓÚ JDK_home\bin Ŀ¼Ï£¬°²×°ºÃ Java SE ºó£¬¿ÉÔÚÃüÁîÐÐÖ±½ÓʹÓà native2ascii ÃüÁî½øÐÐתÂ룬ʾÀý£º
native2ascii -encoding 8859_1 c:\test.txt c:\temp.txt
½« test.txt ÎļþÄÚÈÝÓà 8859_1 × ......
ÎÒÃǶ¼ÖªµÀjava¡¢c#¡¢vbµÈÓïÑÔ¶¼ÓÐsleepÔÝÍ£µÄº¯Êý£¬¶øJavaScript½Å±¾Ã»ÓÐÀàËƵŦÄÜ¡£
ÏÂÃæ¾ÍÊÇÎÒµÄʵÏֵķ½·¨£º
<mce:script type="text/javascript"><!--
function test()
{
var s="javascript--ÔÝÍ£º¯Êý";
setTimeout(
function(){
eval(sleep(test)); //Ö´ÐÐreturnÖ®ºóµÄ´úÂ룬Ҳ¾ÍÊÇ&ldq ......
ÏÂÃæÒÔ±àÒë /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 ......
public static void main(string[] args)
{
int[] arrayInt=new int[] {1,2,3,4,5}
ArrayList alist =ArrayList();
//·½·¨Ò»
foreach(int i in alist)
{
&nbs ......