Java's “clone()” method generator for Eclipse Galileo

╄→гoц情女王★ 提交于 2019-12-23 07:57:03

问题


What is the best tool for java's clone() method generation in Eclipse Galileo available from repositories? What is the reason, that prevents Eclipse developers from including this tool in standard release?


回答1:


It's very hard to implement clone() right. It is considered not a good practice to do so. Bloch (Effective Java) suggest that using clone() should be avoided. Use other means of shallow cloning, like copy-constructors or utilities like commons-beanutils.




回答2:


I absolutely agree with Bozho. However, if there is a need for it and you have large number of member fields to copy over and you need to quick way to list them out then you could make use of the "toString" generator to get a code template.

In the generate toString option use the Code style : "StringBuilder/StringBuffer" which would list all member fields and append to the StringBuilder. Then you could change the appends to appropriate setters of the cloned object.



来源:https://stackoverflow.com/questions/3180599/javas-clone-method-generator-for-eclipse-galileo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!