/**
- */ package bean;
import java.math.BigDecimal;
import java.util.Date;
/**
-
@author hb
*
/
public class JavaBean extends Bean implements Cloneable {
/- 氏名 / private String Name; /
- 年月日 / private Date birthday; /
- アカウント / private String account; /
- パスワード / private String password; /
- 住所 */ private String[] address;
/**
- @return the name */ public String getName() { return Name; }
/**
- @param name
- the name to set */ public void setName(String name) { Name = name; }
/**
- @return the birthday */ public Date getBirthday() { return birthday; }
/**
- @param birthday
- the birthday to set */ public void setBirthday(Date birthday) { this.birthday = birthday; }
/**
- @return the account */ public String getAccount() { return account; }
/**
- @param account
- the account to set */ public void setAccount(String account) { this.account = account; }
/**
- @return the password */ public String getPassword() { return password; }
/**
- @param password
- the password to set */ public void setPassword(String password) { this.password = password; }
/**
- @return the address */ public String[] getAddress() { return address; }
/**
- @param address the address to set */ public void setAddress(String[] address) { this.address = address; }
@Override
protected Object clone() throws CloneNotSupportedException{
JavaBean bean = (JavaBean) super.clone();
return bean;
}public static void main(String[] args) throws Exception {
JavaBean bean = new JavaBean();
bean.setSn(new BigDecimal(1));
bean.setName("123");
bean.setAddress(new String[]{"China","Shanghai","Pudong"});JavaBean cbean = (JavaBean) bean.clone(); cbean.setSn(new BigDecimal(2)); cbean.setName("456"); cbean.setAddress(new String[]{"US","NewYork","NewYork"}); System.out.println(bean); System.out.println(cbean); System.out.println(bean.getSn()); System.out.println(cbean.getSn()); System.out.println(bean.getName().hashCode()+":"+bean.getName()); System.out.println(cbean.getName().hashCode()+":"+cbean.getName()); System.out.println(bean.getAddress().hashCode()+":"+bean.getAddress()[0]); System.out.println(cbean.getAddress().hashCode()+":"+cbean.getAddress()[0]);
}
}
小弟最近在学习Java1.8下 关于浅Clone与深Clone的区别。发现有一些与以前不同的地方 感觉已经没有浅Clone这一说法 重载Clone方法后 对Clone后的对象方法赋值 已经不会改变原Clone对象 难道在Java1.8中取消了浅Clone?请各位大神指点