how can I read generic-type object with object stream?

I declared a class like this

class Storage<K extedns Key, Dextends Data>implements Serializable{

}

class Keyimplements Serializable{

}

interface Dataextends Serializable{

}

and I used ObjectOutputStream to save.

Storage<MyKey, MyData> storage =new Storage<MyKey, MyData>();

ObjectOutputStream out =new ObjectOutputStream(new FileOutputStream(new File("file")));

out.writeObject(storage);

after save code, I tryed to write loading code like

ObjectInputStream in =new ObjectInputStream(new FileInputStream(new File("file")));

Storage<MyKey, MyData> storage = (Storage<MyKey, MyData>)in.readObject();

but, it occurs a casting error. How can I downcast my Object object to Storage<MyKey, MyData> object?

[1504 byte] By [enoaa] at [2007-11-15]
# 1

> ...

> but, it occurs a casting error. How can I downcast my

> Object object to Storage<MyKey, MyData> object?

You probably mean a warning. If that's the case: there is nothing you can do about it except to suppress it:

http://java.sun.com/docs/books/tutorial/java/javaOO/annotations.html

prometheuzza at 2007-7-12 > top of java,Core,Core APIs...
# 2

Gone are the days where one could achieve completely warning free code, it seems since generics has arrived. Is this an ideal compilation environment? What about the rest of us developers that have molded our processes into such where the resulting code compiled without deprecation warnings and all other such warnings? Why does it make us feel as though we're doing something wrong when we suppress a warning, when we really aren't because we know what we are suppressing? why doesn't it feel as squeaky clean as it once did? Are there plans to deal with this in the future or is this how we proceed to develop from now on?

javiousa at 2007-7-12 > top of java,Core,Core APIs...