我们知道在Java中只要实现了Serializable接口,这个都可以被序列化,在Android中进行序列化还有一种方式, 就是Parcelable,
而且比Java提供的序列话方式性能更高,但是在实际的开发中我们有些类虽然实现了Serializable接口,但是里面的有些属性不想进行序列化,这个时候就可以在这个变量的前面添加transient修饰了,
class Rectangle implements Serializable {
private static final long serialVersionUID = 1710022455003682613L;
private Integer width;
private Integer height;
private transient Integer area;
public Rectangle (Integer width, Integer height){
this.width = width;
this.height = height;
this.area = width * height;
}
public void setArea(){
this.area = this.width * this.height;
}
@Override
public String toString() {
return "Rectangle{" +
"width=" + width +
", height=" + height +
", area=" + area +
'}';
}
}
public clas