如果用类作返回值,在JAVA中返回的是地址还是要返回的类的一个拷贝??? public Font getNewFont(){ Font nfont =new Font(ofont.getAttributes()); return nfont;}不知行不行试试看:)) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to 微电你是否是微硬我举的只是一个例子,返回值是我个人作的类,请问如何解决?.clone()函数是什么意思?如何解决? 你是例子,我也是例子啊,作相应改变不就行了:))要实现.clone()函数你必须实现Cloneable 接口 to 小草任何的对象,只要运行其.clone()都能得到一个拷贝吗?在类的继承过程中,要不要对clone()进行处理? 抄段例子自己研究去:))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(System.err); } 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(System.err); } return o; }}class OceanReading implements Cloneable { private DepthReading depth; private TemperatureReading temperature; public OceanReading(double tdata, double ddata){ temperature = new TemperatureReading(tdata); depth = new DepthReading(ddata); } public Object clone() { OceanReading o = null; try { o = (OceanReading)super.clone(); } catch(CloneNotSupportedException e) { e.printStackTrace(System.err); } // Must clone references: o.depth = (DepthReading)o.depth.clone(); o.temperature = (TemperatureReading)o.temperature.clone(); return o; // Upcasts back to Object }}public class DeepCopy { public static void main(String[] args) { OceanReading reading = new OceanReading(33.9, 100.5); // Now clone it: OceanReading r = (OceanReading)reading.clone(); }} ///:~ 因为我调用的类不是自己做的,协作方要求不修改类所以不能对其进行派生,他又没有从Cloneable 派生如何解决? to 微电jixu我使用其它单位做的类,不能修改和派生,但是必须用byval传参,如何实现? 接口中修饰符 DriverManager.getConnection,时间每次需要15-20秒 eclipse(javaee版本)自带了junit,如何查看junit的jar包啊,放在哪个路径下了? java编程 菜鸟问题 想知道JAVA中的参数到底是怎么一回事 java日志的问题 请教一个java内部类的问题 如何判断一个String中含有中文,谢谢 JAVA如何动态从LINUX下获取文件! swing编程问题:如何让JMenuBar下的JMenuItem被选中后变灰,不能再选,或者是使用其它类? 学会JAVA要用多长时间(能混饭吃的程度)! 程序如下,请高手指点!!!!!!
你是否是微硬
我举的只是一个例子,返回值是我个人作的类,请问如何解决?
.clone()函数是什么意思?如何解决?
任何的对象,只要运行其.clone()都能得到一个拷贝吗?
在类的继承过程中,要不要对clone()进行处理?
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(System.err);
}
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(System.err);
}
return o;
}
}class OceanReading implements Cloneable {
private DepthReading depth;
private TemperatureReading temperature;
public OceanReading(double tdata, double ddata){
temperature = new TemperatureReading(tdata);
depth = new DepthReading(ddata);
}
public Object clone() {
OceanReading o = null;
try {
o = (OceanReading)super.clone();
} catch(CloneNotSupportedException e) {
e.printStackTrace(System.err);
}
// Must clone references:
o.depth = (DepthReading)o.depth.clone();
o.temperature =
(TemperatureReading)o.temperature.clone();
return o; // Upcasts back to Object
}
}public class DeepCopy {
public static void main(String[] args) {
OceanReading reading =
new OceanReading(33.9, 100.5);
// Now clone it:
OceanReading r =
(OceanReading)reading.clone();
}
} ///:~
所以不能对其进行派生,他又没有从Cloneable 派生
如何解决?
jixu
我使用其它单位做的类,不能修改和派生,但是必须用byval传参,如何实现?