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Á÷½øÐвÙ×÷¡£½øÒ»²½Ëµ£¬Èç¹ûËüÃÇÁ½¸öÖеÄÒ»¸ö¹Ø±ÕÁ
Ïà¹ØÎĵµ£º
ClassLoaderÒ»¸ö¾³£³öÏÖÓÖÈúܶàÈËÍû¶øÈ´²½µÄ´Ê£¬±¾ÎĽ«ÊÔͼÒÔ×îdzÏÔÒ׶®µÄ·½Ê½À´½²½â ClassLoader£¬Ï£ÍûÄܶԲ»Á˽â¸Ã»úÖƵÄÅóÓÑÆðµ½Ò»µãµã×÷Óá£
ÒªÉîÈëÁ˽âClassLoader£¬Ê×ÏȾÍÒªÖªµÀClassLoaderÊÇÓÃÀ´¸ÉʲôµÄ£¬¹ËÃû˼Ò壬Ëü¾ÍÊÇÓÃÀ´¼ÓÔØClassÎļþµ½JVM£¬ÒÔ¹©³ÌÐòʹÓõġ£ÎÒÃÇÖªµÀ£¬java³ÌÐò¿ÉÒÔ¶¯Ì¬¼ÓÔØÀඨÒ壬¶øÕâ ......
¹ØÓÚjavaµÄ¼¯ºÏÀà,ÒÔ¼°HashMapÖÐSetµÄÓ÷¨!
2005-10-22 14:47:43 Sat | ÔĶÁ£¨547£©´Î
package com.tiantian;
import java.util.*;
public class JAVAContainer {
public static void main(String[] args) throws Exception {
//&nbs ......
1. Ê×ÏÈString²»ÊôÓÚ8ÖÖ»ù±¾Êý¾ÝÀàÐÍ£¬StringÊÇÒ»¸ö¶ÔÏó¡£
¡¡¡¡ÒòΪ¶ÔÏóµÄĬÈÏÖµÊÇnull£¬ËùÒÔStringµÄĬÈÏÖµÒ²ÊÇnull£»µ«ËüÓÖÊÇÒ»ÖÖÌØÊâµÄ¶ÔÏó£¬ÓÐÆäËü¶ÔÏóûÓеÄһЩÌØÐÔ¡£
¡¡¡¡2. new String()ºÍnew String(“”)¶¼ÊÇÉêÃ÷Ò»¸öеĿÕ×Ö·û´®£¬ÊÇ¿Õ´®²»ÊÇnull£»
¡¡¡¡3. String str=”kvill”£»
......
¹¤×÷ÒѾÓаëÄêÁË£¬Í»È»Ïëдµã¶«Î÷£¬´óѧµÄʱºò¾ÍÓÐдÈռǵÄÏ°¹ß£¬µ«ÊÇ×Ô´ÓÈ¥Java06°àѧϰһֱµ½ÏÖÔÚ¹¤×÷£¬ÂýÂýµÄҲûÓÐʱ¼äȥдÈռǣ¬Ï£Íûͨ¹ýÕâƪÎÄÕÂÄÜÈÃJava˽ÛÓµÄѧµÜѧÃÃÃÇ¿´ÁËÓÐËù°ïÖú¡£
ÏàÐźܶàͬѧºÜÎÒÒ»Ñù´óËĵÄʱºò¶¼±È½ÏÃÔ㣬ÓÈÆäÊÇÎÒ¶ÁµÄ¼ÆËã»úרҵ£¬ËµÊµ»°´óѧÀïѧµÄºÍÉç»áʵ¼ÊÐèÒªµÄ» ......