深拷贝
来源:互联网 发布:网络销售总监 编辑:程序博客网 时间:2024/05/01 18:43
class DepthReading implements Cloneable{
private double depth;
public DepthReading(double depth) {
this.depth = depth;
}
public Object clone(){
Object o = null;
try {
o = super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return o;
}
}
class TemperatureReading implements Cloneable{
private long time;
private double temperature;
public TemperatureReading(double temperature) {
time = System.currentTimeMillis();
this.temperature = temperature;
}
public Object clone(){
Object o = null;
try {
o = super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return o;
}
}
class OceanReading implements Cloneable{
private DepthReading depth;
private TemperatureReading temperature;
public OceanReading(double tdata, double ddate) {
temperature = new TemperatureReading(tdata);
depth = new DepthReading(ddate);
}
public Object clone(){
OceanReading o = null;
try {
o = (OceanReading)super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
o.depth = (DepthReading)o.depth.clone();
o.temperature = (TemperatureReading)o.temperature.clone();
return o;
}
}
public class DeepCopy {
public static void main(String[] args) {
OceanReading reading = new OceanReading(33.9, 100.5);
OceanReading r = (OceanReading)reading.clone();
}
}
private double depth;
public DepthReading(double depth) {
this.depth = depth;
}
public Object clone(){
Object o = null;
try {
o = super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return o;
}
}
class TemperatureReading implements Cloneable{
private long time;
private double temperature;
public TemperatureReading(double temperature) {
time = System.currentTimeMillis();
this.temperature = temperature;
}
public Object clone(){
Object o = null;
try {
o = super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return o;
}
}
class OceanReading implements Cloneable{
private DepthReading depth;
private TemperatureReading temperature;
public OceanReading(double tdata, double ddate) {
temperature = new TemperatureReading(tdata);
depth = new DepthReading(ddate);
}
public Object clone(){
OceanReading o = null;
try {
o = (OceanReading)super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
o.depth = (DepthReading)o.depth.clone();
o.temperature = (TemperatureReading)o.temperature.clone();
return o;
}
}
public class DeepCopy {
public static void main(String[] args) {
OceanReading reading = new OceanReading(33.9, 100.5);
OceanReading r = (OceanReading)reading.clone();
}
}
0 0
- 深拷贝&&浅拷贝
- 深拷贝||浅拷贝
- 浅拷贝,深拷贝
- 浅拷贝,深拷贝
- 深拷贝,浅拷贝
- 浅拷贝 深拷贝
- 浅拷贝.深拷贝
- 浅拷贝 深拷贝
- 深拷贝,浅拷贝
- 深拷贝、浅拷贝
- 深拷贝、浅拷贝
- 深拷贝+浅拷贝
- 深拷贝 浅拷贝
- 浅拷贝、深拷贝
- 浅拷贝、深拷贝
- 深拷贝、浅拷贝
- 深拷贝,浅拷贝
- 深拷贝、浅拷贝
- 采药
- Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL
- 使用java创建netcdf文件,并写入数据
- 十字图蓝桥杯
- Java基础.io流字节流.复制图片
- 深拷贝
- 知识点总结
- Spark知识体系完整解读
- 使用Jetbrains的Gogland IDE阅读Consul源码
- 多字节转UTF-8
- 用Tomcat服务器配置https双向认证过程实战
- 面向对象程序设计 授课计划
- 96. Unique Binary Search Trees
- 复现 OOM