想克隆一个输入流对象
类:
class CloneTest implements Cloneable{
public InputStream inputStream = null;
public CloneTest(InputStream inputStream){
this.inputStream = inputStream;
}
public Object clone() throws CloneNotSupportedException {
CloneTest cloneTest = (CloneTest)super.clone();
return cloneTest;
}
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
}
调用的代码:
CloneTest ct = new CloneTest(inputStream);
CloneTest ct2 = (CloneTest)ct.clone();
InputStream inputStream2 = ct2.getInputStream();
这里得到的inputStream2和传进去的参数inputStream还是同一个对象,如何克隆呢?