开发者

Java's "clone()" method generator for Eclipse Galileo

开发者 https://www.devze.com 2023-01-06 06:22 出处:网络
What is the best tool for java\'s clone() method generation in Eclipse Galileo av开发者_开发知识库ailable from repositories?

What is the best tool for java's clone() method generation in Eclipse Galileo av开发者_开发知识库ailable from repositories? What is the reason, that prevents Eclipse developers from including this tool in standard release?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消