Originally posted by Arul Prasad:
Yes I have also think that reason. but if Collection can use the Genrics . why can't this ObjectOutputStream and ObjectInputStream .
It could, but it would be of much less value.
When you have a List<Animal>, the compiler makes sure that only Animals are put into the list. So if you get an object from the list, you can be very sure that it *must* be an Animal.
When you have an ObjectInputStream<Animal>, the input is just a binary stream. The compiler can't guarantee that the stream was produced using an ObjectOutputStream<Animal>, so we actually don't know what the stream actually contains.
So, for a list, if you use generics consequently, you can be quite sure that you will never get a ClassCastException - the compiler would already find out about the problem. That's simply not possible for the streams, because you use two different objects to write and read the stream.
Does that sound reasonable?