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]
# 1
You'll need to do this famRestore = (List<String>) restore.readObject();I tested and it's working. Don't forget to transfer the DUKE Dollars :).
Srini_Kandulaa at 2007-7-10 2:57:08 > top of Java-index,Core,Core APIs...
# 2
Can you tell me exactly whatthis snippet of code does? Im I just casting the object?
melikaia at 2007-7-10 2:57:08 > top of Java-index,Core,Core APIs...
# 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());

Srini_Kandulaa at 2007-7-10 2:57:08 > top of Java-index,Core,Core APIs...
# 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?
melikaia at 2007-7-10 2:57:08 > top of Java-index,Core,Core APIs...
# 5
Go through the Generics tutorial when you have time. http://java.sun.com/docs/books/tutorial/extra/generics/index.html
Srini_Kandulaa at 2007-7-10 2:57:08 > top of Java-index,Core,Core APIs...