Hello,
I feel a dilemma with the following code: generics are of no use to ObjectInputStream.readObject() ...
static HashMap<Integer,Character> map= new HashMap<Integer,Character>();
ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream
(new FileInputStream("myFile")));
map = (HashMap)ois.readObject(); // [unchecked] unchecked conversion
map.put(new Integer(nr), new Character(c));
... but after removing the generics from the HashMap definition, now HashMap.put(...) asks for them.
static HashMap map= new HashMap();
ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream
(new FileInputStream("myFile")));
map = (HashMap)ois.readObject();
map.put(new Integer(nr), new Character(c)); // [unchecked] unchecked call to put(K,V)
A cast like
map = (HashMap<Integer,Character>)ois.readObject();
is not possible (G. Bracha's Tutorial, 7.2).
Is there still a way to satisfy the compiler?
Greetings
J�rg