o****i 发帖数: 1706 | 1 public Date clone(){
Date date=null;
try {
date=(Date)super.clone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return date;
}
public Date clone(){
return date.clone();
}
这个是否等效呢?有什么区别吗?谢谢! |
b******y 发帖数: 9224 | 2 感觉应该一样的效果。一般自己写clone() method,是需要在 super.clone()完后再加上一些本method应该的设置.
简单的例子. 如果super class定义了 isClone,
在super.clone()之后,就可以写:
isClone = true;
但如果和super class 没有任何区别的话,我觉得两种方法都等同。 |
h*****0 发帖数: 4889 | 3 第二个方法里的date是啥?
【在 o****i 的大作中提到】 : public Date clone(){ : Date date=null; : try { : date=(Date)super.clone(); : } catch (CloneNotSupportedException e) { : // TODO Auto-generated catch block : e.printStackTrace(); : } : return date; : }
|
o****i 发帖数: 1706 | 4 date is my own made class ah.. from my hw.. |
o****i 发帖数: 1706 | 5 opss..I think i made a mistake in second one, it should be Date.clone()... |
h*****0 发帖数: 4889 | 6 so your class is a sub class from Date?
then super.clone and Date.clone should be the same.
【在 o****i 的大作中提到】 : opss..I think i made a mistake in second one, it should be Date.clone()...
|
h*****0 发帖数: 4889 | 7 but the first one is not a very good one, since it will return a null if
exception happens.
【在 o****i 的大作中提到】 : opss..I think i made a mistake in second one, it should be Date.clone()...
|
o****i 发帖数: 1706 | |