Redian新闻
>
Why Java needs clone interface?
avatar
Why Java needs clone interface?# Java - 爪哇娇娃
g*g
1
Folks, I am confused when one needs to implement clone interface
in java, can't java just copy memory like C++?
avatar
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++?

avatar
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.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。