JavaÖеÄÉÖÆÓëdz¸´ÖÆ
1£®Ç³¸´ÖÆÓëÉÖƸÅÄî
¢Ådz¸´ÖÆ£¨Ç³¿Ë¡£©
±»¸´ÖƶÔÏóµÄËùÓбäÁ¿¶¼º¬ÓÐÓëÔÀ´µÄ¶ÔÏóÏàͬµÄÖµ£¬¶øËùÓеĶÔÆäËû¶ÔÏóµÄÒýÓÃÈÔȻָÏòÔÀ´µÄ¶ÔÏó¡£»»ÑÔÖ®£¬Ç³¸´Öƽö½ö¸´ÖÆËù¿¼ÂǵĶÔÏ󣬶ø²»¸´ÖÆËüËùÒýÓõĶÔÏó¡£
¢ÆÉÖÆ£¨Éî¿Ë¡£©
±»¸´ÖƶÔÏóµÄËùÓбäÁ¿¶¼º¬ÓÐÓëÔÀ´µÄ¶ÔÏóÏàͬµÄÖµ£¬³ýÈ¥ÄÇЩÒýÓÃÆäËû¶ÔÏóµÄ±äÁ¿¡£ÄÇЩÒýÓÃÆäËû¶ÔÏóµÄ±äÁ¿½«Ö¸Ïò±»¸´ÖƹýµÄжÔÏ󣬶ø²»ÔÙÊÇÔÓеÄÄÇЩ±»ÒýÓõĶÔÏó¡£»»ÑÔÖ®£¬ÉÖÆ°ÑÒª¸´ÖƵĶÔÏóËùÒýÓõĶÔÏ󶼸´ÖÆÁËÒ»±é¡£
2£®JavaµÄclone()·½·¨
¢Åclone·½·¨½«¶ÔÏó¸´ÖÆÁËÒ»·Ý²¢·µ»Ø¸øµ÷ÓÃÕß¡£Ò»°ã¶øÑÔ£¬clone£¨£©·½·¨Âú×㣺
¢Ù¶ÔÈκεĶÔÏóx£¬¶¼ÓÐx.clone() !=x//¿Ë¡¶ÔÏóÓëÔ¶ÔÏó²»ÊÇͬһ¸ö¶ÔÏó
¢Ú¶ÔÈκεĶÔÏóx£¬¶¼ÓÐx.clone().getClass()= =x.getClass()//¿Ë¡¶ÔÏóÓëÔ¶ÔÏóµÄÀàÐÍÒ»Ñù
¢ÛÈç¹û¶ÔÏóxµÄequals()·½·¨¶¨ÒåÇ¡µ±£¬ÄÇôx.clone().equals(x)Ó¦¸Ã³ÉÁ¢¡£
¢ÆJavaÖжÔÏóµÄ¿Ë¡
¢ÙΪÁË»ñÈ¡¶ÔÏóµÄÒ»·Ý¿½±´£¬ÎÒÃÇ¿ÉÒÔÀûÓÃObjectÀàµÄclone()·½·¨¡£
¢ÚÔÚÅÉÉúÀàÖи²¸Ç»ùÀàµÄclone()·½·¨£¬²¢ÉùÃ÷Ϊpublic¡£
¢ÛÔÚÅÉÉúÀàµÄclone()·½·¨ÖУ¬µ÷ÓÃsuper.clone()¡£
¢ÜÔÚÅÉÉúÀàÖÐʵÏÖCloneable½Ó¿Ú¡£
Çë¿´ÈçÏ´úÂ룺
public class Student implements Cloneable
{
int age;
String name;
Professor p;
public Student(int age, String name, Professor p) {
this.age = age;
this.name = name;
this.p = p;
}
public Object clone() {
Student o = null;
try {
o = (Student) super.clone();//ObjectÖеÄclone()ʶ±ð³öÄãÒª¸´ÖƵÄÊÇÄÄÒ»¸ö¶ÔÏó¡£
} catch (Exception e) {
System.out.println(e.toString());
}
return o;
}
public static void main(String[] args) {
Professor p = new Professor(40, "poul");
Student stu1 = new Student(18, "pitt", p);
Student stu2 = (Student)stu1.clone();
stu2.p.name = "wang";//ÐÞ¸ÄѧÉú2ºó£¬²»Ó°ÏìѧÉú1µÄÖµ¡£
stu2.p.age = 12;
System.out.println("stu1.p.name=" + stu1.p.name
+ ",stu1.p.age=" + stu1.p.a
Ïà¹ØÎĵµ£º
JAVAµÄÈÝÆ÷---List,Map,Set
Collection
©ÀList
©¦©ÀLinkedList
©¦©ÀArrayList
©¦©¸Vector
©¦¡¡©¸Stack
©¸Set
Map
©ÀHashtable
©ÀHashMap
©¸WeakHashMap
Collection½Ó¿Ú
¡¡¡¡CollectionÊÇ×î»ù±¾µÄ¼¯ºÏ½Ó¿Ú£¬Ò»¸öCollection´ú±íÒ»×éObject£¬¼´CollectionµÄÔªËØ£¨Elements£©¡£Ò»Ð© CollectionÔÊÐíÏà ......
±íÃæÉÏ¿´ÆðÀ´£¬ÎÞÂÛÓï·¨»¹ÊÇÓ¦ÓõĻ·¾³£¨±ÈÈçÈÝÆ÷Àࣩ£¬·ºÐÍÀàÐÍ£¨»òÕß·ºÐÍ£©¶¼ÀàËÆÓÚ C++ ÖеÄÄ£°å¡£µ«ÊÇÕâÖÖÏàËÆÐÔ½öÏÞÓÚ±íÃ棬Java ÓïÑÔÖеķºÐÍ»ù±¾ÉÏÍêÈ«ÔÚ±àÒëÆ÷ÖÐʵÏÖ£¬ÓɱàÒëÆ÷Ö´ÐÐÀàÐͼì²éºÍÀàÐÍÍƶϣ¬È»ºóÉú³ÉÆÕͨµÄ·Ç·ºÐ͵Ä×Ö½ÚÂë¡£ÕâÖÖʵÏÖ¼¼Êõ³ÆΪ²Á³ý£¨erasure£©£¨±àÒëÆ÷ʹÓ÷ºÐÍÀàÐÍÐÅÏ¢±£Ö¤ÀàÐÍ°²È«£¬È»ºóÔ ......
//package ÓéÀÖ;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.text.DecimalFormat;
import javax.swing ......