What is the best procedure for storing and retrieving, using native Java serialization, generic objects like ArrayList<String>?
Edit: To clarify. When I serialize an object of type ArrayList<String> I'd like to de-serialize to the same type of object. However, I know of no way to cast back to this generic object without causing warnings.
I think I understand the question, though it could be stated less vaguely. When you deserialize, you could cast to raw ArrayList and as long as that doesn't throw a ClassCastException you know you got that part right; but if you further cast to ArrayList<String> (or List<String>), you'll get a warning that this is not safe. The collection might contain Integers and this cast alone won't catch that.
The usual best course of action is just to match your serialization and deserialization code to each other carefully, and suppress the warnings that result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With