对象 序列化 实现深拷贝

Feature feature = new Feature();

f[i]=(Feature)feature.deepClone();

 

public class Feature  implements Serializable{
 private GeoType geometry;
    private String type;
    private Property properties;
    private int id;
 
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public GeoType getGeometry() {
  return geometry;
 }
 public void setGeometry(GeoType geometry) {
  this.geometry = geometry;
 }
 public String getType() {
  return type;
 }
 public void setType(String type) {
  this.type = type;
 }
 public Property getProperties() {
  return properties;
 }
 public void setProperties(Property properties) {
  this.properties = properties;
 }
 
 public Object deepClone() throws IOException,OptionalDataException,ClassNotFoundException{
    //将对象写到流里
    ByteArrayOutputStream bo=new ByteArrayOutputStream();
    ObjectOutputStream oo=new ObjectOutputStream(bo);
    oo.writeObject(this);
    //从流里读出来
    ByteArrayInputStream bi=new ByteArrayInputStream(bo.toByteArray());
    ObjectInputStream oi=new ObjectInputStream(bi);
    return(oi.readObject());
  }

}

 

记住类要序列化 深层类继续序列化

你可能感兴趣的:(return,id,Class,private,public)