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

2

9

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?

Unsuccessful answered 5/7, 2010 at 15:18 Comment(1)
You may want to ask this on the eclipse forums. There you may get an answer from the eclipse developers.Nimrod
F
12

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.

Form answered 5/7, 2010 at 15:40 Comment(0)
R
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.

Reprehend answered 2/8, 2016 at 17:9 Comment(1)
thx, we can further use notepad++ to fastly create a simple keyboard macro and make most changes quite fastly, as I remember it also has plugins for ex. captalize the 1st letter if we need tooLincoln

© 2022 - 2024 — McMap. All rights reserved.