Retore Serialized arraylist
I have created an array list. I know how to save the of the list, but is it possale to restore it back into the list. Every time I try to restore the state of the array list I keep getting an error 'found: java.lang.Object
required: java.util.List<java.lang.String>. When i try to restore the state into an Arraylist I get the same error. What am I doing wrong? is it possiable to restore the state of the list and append to it?
here is what I have List<String> famRestore =new ArrayList<String>();
ObjectInputStream restore =new ObjectInputStream(new FileInputStream("TempData.dat"));
famRestore = restore.readObject();
Thanks for the Help
[822 byte] By [
melikaia] at [2007-11-26 21:18:17]

# 3
Since the famRestore is of type List<String> you'll have to cast the readObject to List<String>. When you are using Generics you need to be bit careful abt casting. Of course we have autoboxing and outboxing features provided, but only for primitives.
This is the code snippet I have to test this.
List<String> famRestore = new ArrayList<String>();
famRestore.add("one");
famRestore.add("two");
ObjectOutputStream writeObj = new ObjectOutputStream(new FileOutputStream("TempData.dat"));
writeObj.writeObject(famRestore);
ObjectInputStream restore = new ObjectInputStream(new FileInputStream("TempData.dat"));
famRestore = (List<String>) restore.readObject();
System.out.println("Size is"+ famRestore.size());
# 4
Your great, I had this injuntion w/ another list and I t did work successfully. I just wasn't sure as to what was happing. Im howevere getting the warning, something about un-safe operation. What are the hazards w/ casting like that?