package com.lovo.bean.src.com.lovo.clone;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class BasketballStar implements Cloneable,Serializable {
private String name;
private float height;
private float weight;
private int age;
private Skill theSkill;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Skill getTheSkill() {
return theSkill;
}
public void setTheSkill(Skill theSkill) {
this.theSkill = theSkill;
}
//浅克隆
public BasketballStar clone() throws CloneNotSupportedException {
BasketballStar bs = (BasketballStar) super.clone();
Skill theSkillClone = this.getTheSkill().clone();
bs.setTheSkill(theSkillClone);
return bs;
}
//深克隆
public BasketballStar deepClone() throws IOException, ClassNotFoundException{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(this);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
return (BasketballStar)ois.readObject();
}
}