用OO思想优化代码

xjde1314
06-05-27 1 134

public Object createCopy(Object source) {

if (source instanceof Integer) {
return new Integer(((Integer)source).intValue());
}
if (source instanceof Long) {
return new Long(((Long)source).longValue());
}
if (source instanceof Float) {
return new Float(((Float)source).floatValue());
}
return null;
}

banq
2006-05-29 15:37

用这么长if else就不是OO了吧?