javaÖеÄclon()ºÍcloneable½Ó¿ÚdzÎö
The clone( ) method generates a duplicate copy of the object on which it is called. Only classes that implement the Cloneable interface can be cloned.
...clone()²úÉúÁËÒ»¸öµ÷ÓÃËüµÄ¶ÔÏóµÄ¸´ÖÆ;Ö»ÓÐʵÏÖÁËCloneable½Ó¿ÚµÄÀà²Å¿ÉÒÔ±»¸´ÖÆ¡£
The Cloneable interface defines no members. It is used to indicate that a class allows a bitwise copy of an object (that is, a clone ) to be made. If you try to call clone( ) on a class that does not implement Cloneable , a CloneNotSupportedException is thrown. When a clone is made, the constructor for the object being cloned is not called. A clone is simply an exact copy of the original.
Cloneable ½Ó¿ÚûÓж¨ÒåÈκγÉÔ±¡£ËüÓÃÀ´Ö¸Ã÷Ò»¸öÀà¿ÉÒÔÖðλ¸´ÖÆÒ»¸ö¶ÔÏó¡£Èç¹ûÄãÊÔͼ¶ÔÒ»¸öûÓÐʵÏÖcloneable½Ó¿ÚµÄÀàµ÷ÓÃclone()·½·¨£¬Ò»¸öCloneNotSupportedException ¾Í»áÅ׳ö¡£ÔÚ¸´ÖÆʱ£¬±»¸´ÖƵĶÔÏóµÄ¹¹ÔìÆ÷²¢Ã»Óб»µ÷Ó᣸´ÖƶÔÏó¾ÍÊÇÔÀ´¶ÔÏóµÄ¿½±´¡£
Cloning is a potentially dangerous action, because it can cause unintended side effects. For example, if the object being cloned contains a reference variable called obRef, then when the clone is made, obRef in the clone will refer to the same object as does obRef in the original. If the clone makes a change to the contents of the object referred to by obRef, then it will be changed for the original object, too. Here is another example. If an object opens an I/O stream and is then cloned, two objects will be capable of operating on the same stream. Further, if one of these objects closes the stream, the other object might still attempt to write to it, causing an error.
¸´ÖÆÊÇÒ»ÖÖ´æÔÚDZÔÚΣÏÕµÄÐÐΪ£¬ÒòΪËü»áÒýÆðһЩÒâÏë²»µ½µÄ¸º×÷Óá£ÀýÈ磬Èç¹û±»¸´ÖƵĶÔÏó°üº¬Ò»¸öÃûΪ obRef ÒýÓñäÁ¿£¬ÔÚ¸´ÖÆʱ£¬¸´ÖƶÔÏóµÄ obReºÍf ÔÀ´¶ÔÏóµÄ obRef ¶¼»áÖ¸Ïòͬһ¸ö¶ÔÏó¡£Èç¹û¸´ÖƶÔÏó¶Ô obRef Ö¸ÏòµÄ¶ÔÏóµÄÄÚÈÝ×ö³öһЩ¸Ä±ä£¬¶ÔÓÚÔÀ´¶ÔÏóÀ´Ëµ£¬Ò²¾ÍÏ൱ÓÚËüÒ²±»¸Ä±äÁË¡£»¹ÓÐÁíÒ»¸öÀý×Ó£¬Èç¹ûÒ»¸ö²Ù×÷I/OÁ÷µÄ¶ÔÏ󱻸´ÖÆÁË£¬ÕâÁ½¸ö¶ÔÏó¶¼ÄܶÔͬһI/OÁ÷½øÐвÙ×÷¡£½øÒ»²½Ëµ£¬Èç¹ûËüÃÇÁ½¸öÖеÄÒ»¸ö¹Ø±ÕÁ
Ïà¹ØÎĵµ£º
<!--
/* Font Definitions */
@font-face
{font-family:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:ËÎÌå;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@SimSun&qu ......
ÏÂÃæÕâƪÎÄÕÂÊÇ̨ÍåÖøÃûJavaÂÛ̳“Javaworld”µÄÒ»¸ö×ÊÉî°æÖ÷дµÄÒ»·â¶ÔJavaÐÂÊÖµÄÐÅ£¬Ï£ÍûС×é³ÉÔ±×Ðϸ¿´Ï Äã»áѧµ½ºÜ¶àµÄ¡¢¡¢¡¢¡¢
親愛µÄ java ÐÂÊÖ們 :
ºÜ¸ß興Äã們願Òâ來這裡¹²Í¬學習,
Java 這個語ÑÔ, ÒÑ ......
¼øÓÚÅÀ³æ¿ª·¢ÐèÒªÒ»¸öͼƬ½âÎö¹¦Äܵĺ¯Êý£¬µ½ÍøÂçÉϲéÕÒÁËһЩjni·½ÃæµÄÄÚÈÝ£¬²¢×öÁË×Ô¼ºµÄһЩÐ޸ģ¬¾ßÌåÈçÏ£º
Ä¿Ç°javaÓëdll½»»¥µÄ¼¼ÊõÖ÷ÒªÓÐ3ÖÖ£ºjni£¬jawinºÍjacob¡£Jni£¨Java Native Interface£©ÊÇsunÌṩµÄjavaÓëϵͳÖеÄÔÉú·½·¨½»»¥µÄ¼¼Êõ£¨ÔÚwindows\linuxϵͳÖУ¬ÊµÏÖjavaÓënative method»¥µ÷£©¡£ ......
Java¶ÔÏóXMLÐòÁл¯¿ò¼Ü£Simple2.0
SimpleÊÇÒ»¸öXMLÐòÁл¯¿ò¼Ü£¬Ò»¸öJava
°æ±¾¿íÈݵÄÐòÁл¯¿ò¼Ü£¬Äܹ»¿ìËÙÔÚJava
ƽ̨ÉÏ¿ª·¢XML¡£Ö§³Öͨ¹ýannotationsÍêÈ«ÅäÖû¯µÄXML½á¹¹£»Ìṩ°æ±¾¹ÜÀí¿ò¼ÜÔÊÐíÏòÇ°ºÍÏòºó¼æÈÝÐòÁл¯£»¸üºÃµÄÐÔÄÜ£¬Ê¹ÓÃÇáÁ¿¼¶StAXÌáÉýXML·´ÐòÁл¯
½ø³Ì£¬±ÈXStreamºÍJAXB¸ü¿ì£»Í¨¹ýnamespace ......
×î½üÒªÖØÐÂѧϰJava£¬ÕÒ¸öÀý×ÓÀ´Êµ¼ù£¬ÔÚÍøÉÏÕÒÁ˺ܶàÀý³ÌÀ´¿´£¬×Ô¼ºÖØбàдÁËÒ»¸ö̰ʳÉßµÄÀý×Ó£¬¼ÇÔÚÕâÀï¡£
1.SnakeModel.java
import java.util.Observable;
import java.util.LinkedList;
import java.util.Arrays;
import java.util.Random;
import javax.swing.*;
//ObservableÀàÒ»°ã´ú±íÊý¾Ý£¬ÊµÏÖ½Ó¿ÚRunna ......