Folks, I am confused when one needs to implement clone interface in java, can't java just copy memory like C++?
c*t
2 楼
You can't do copy memory on a DAG. The result would be a tree. You can't copy undirected graph or direct graph w/ circular structures.
【在 g*****g 的大作中提到】 : Folks, I am confused when one needs to implement clone interface : in java, can't java just copy memory like C++?
m*t
3 楼
IMHO, the actual reason is Java has to let the programmer decide whether to make deep or shallow copy while cloning. In some cases, a hybrid of deep and shallow copy is also possible. Also, while it's not hard for Java to provide a generic clone utility, it would have to be based on reflection (similar to how serialization works), which could be faily expensive operations.