📄 monkey.java
字号:
package com.javapatterns.prototype.monkeyking2;
import java.io.*;
import java.util.Date;
public class Monkey implements Cloneable, Serializable
{
private int height;
private int weight;
private GoldRingedStaff staff;
private Date birthDate;
public Monkey()
{
this.birthDate = new Date();
this.staff = new GoldRingedStaff();
}
public Object deepClone()
throws IOException, OptionalDataException, ClassNotFoundException
{
//write to stream
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream oo = new ObjectOutputStream(bo);
oo.writeObject(this);
//read from stream
ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
ObjectInputStream oi = new ObjectInputStream(bi);
return (oi.readObject());
}
public Object clone()
{
Monkey temp = null;
try
{
temp = (Monkey)super.clone();
}
catch (CloneNotSupportedException e)
{
System.out.println("Clone failed");
}
finally
{
return temp;
}
}
public int getHeight()
{
return height;
}
public void setHeight(int height)
{
this.height = height;
}
public int getWeight()
{
return weight;
}
public void setWeight(int weight)
{
this.weight = weight;
}
public Date getBirthDate()
{
return birthDate;
}
public void setBirthDate(Date birthDate)
{
this.birthDate = birthDate;
}
public GoldRingedStaff getStaff()
{
return staff;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -