![]() |
Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
As far as I can see, there is no difference. I haven't used the clone method before, but if the clone method clones the whole object (and not just the reference), then it shouldn't matter. There might be memory issues that are also involved, but I know of none. In this case I would probably go with the first method (creating the object 10 times) because it's less code. Any differing opinions? > I have to create 10 objects in a for loop. I am considering to do it in two ways. One is explicitly create the object with new operator. The second one is to create the object with new operator once and clone it 9 times. (Of cource I will call the setXXX methods of the class to change the values after cloning). Which stategy is better? Creating 10 times with new or cloning the object. > for (loop:10 times) { > OR > x x1 = new x(); > for (loop:9 times) { > Please advise.
Replies: |
Sponsored Links
|