Paul Weaver
04-30-2001, 10:35 PM
Java is just designed to make my life complicated. I have a big object that stores quite a few different objects, primative arrays, and object arrays. It's created by reading from a couple of files, and the datas stored. No problem.
I want to use this object a few times though - the same data having been read, but the methods that are called after the inititialisation would be different - sand store different values.
(If you've kept up, well done, its 3:30AM and I'm tired and ranting).
I figured, no problem, just before the loop round I'll copy the Object and then copy it back, giving me a fresh start each loop.
HA!
OK,
baseObj = Obj; wont work, as its just a reference. Wheres the methods to copy the object without a reference though? Yep, .clone()
Of course, this only works if objects are specifcally cloneable. I've tried implements Cloneable though. Couldnt get it to work.
Even if I had though, Java In a nutshell informs me that thats just shallow cloneing, I think it means that all the objects used inside are referenced to each other anyway.
It's too late, and, although I've learnt a lot obout java in the past hour or so, it doesnt help this code has to be finished ASAP for testing, debugging, reporting and handing in by 10AM friday.
ARGHH!!!
All I want is
public Object java.lang.Object.createCopy();
but noo!
I think I can reset the stuff manually, but it will be much harder.
GRRRR.
I want to use this object a few times though - the same data having been read, but the methods that are called after the inititialisation would be different - sand store different values.
(If you've kept up, well done, its 3:30AM and I'm tired and ranting).
I figured, no problem, just before the loop round I'll copy the Object and then copy it back, giving me a fresh start each loop.
HA!
OK,
baseObj = Obj; wont work, as its just a reference. Wheres the methods to copy the object without a reference though? Yep, .clone()
Of course, this only works if objects are specifcally cloneable. I've tried implements Cloneable though. Couldnt get it to work.
Even if I had though, Java In a nutshell informs me that thats just shallow cloneing, I think it means that all the objects used inside are referenced to each other anyway.
It's too late, and, although I've learnt a lot obout java in the past hour or so, it doesnt help this code has to be finished ASAP for testing, debugging, reporting and handing in by 10AM friday.
ARGHH!!!
All I want is
public Object java.lang.Object.createCopy();
but noo!
I think I can reset the stuff manually, but it will be much harder.
GRRRR.