| Author |
Deep cloning not working
|
nitinram agarwal
Ranch Hand
Joined: Jan 29, 2009
Posts: 77
|
|
Hi,
I was doing some exercise as part of self learning to implement different sort algorithm and as an additional test, wanted to experiment with deep cloning as well. however the deep cloning is not working in the intended way. may be I am missing something obvious but am not able to get it and hence need some advice. here is the code
and here is the output
before sorting the array is -
10,15,5,91,14,
after sorting the array is -
5,10,14,15,91,
copied array
5,10,14,15,91,
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3791
|
|
|
What were you expecting the result to be? You sort the array, then you take a copy. So the copy is going to match the sorted array. Are you sure you're doing things in the order you intended?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Also, your clone() method isn't written quite well. You shouldn't use new to create clones, or sub classes cannot override clone() well. I suggest you change it to this, also keeping the CloneNotSupportedException local to the clone() method:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32644
|
|
|
And why are you using Integers rather than ints in an array called intArray?
|
 |
 |
|
|
subject: Deep cloning not working
|
|
|