【发布时间】:2011-04-12 01:53:49
【问题描述】:
在这种情况下克隆是好的做法吗?如何做得更好?
public ModelCollection startParsing() {
return parseFeed(new ModelSpecialEntry);
}
public ModelCollection parseFeed(ModelEntry pattern) {
ModelCollection modelCollection = new ModelCollection();
while( condition ) {
//TODO: Is cloning the best solution?
ModelEntry model = (ModelEntry) pattern.clone();
model.parse();
//add this item to an collection
modelCollection.add(model);
}
return modelCollection;
}
【问题讨论】:
-
' 在这种情况下?你能详细说明一下吗
-
首先告诉我们为什么需要克隆这个对象。
-
因为我想包装一个包含模型的集合。