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
ArrayListand as long as that doesn’t throw aClassCastExceptionyou know you got that part right; but if you further cast toArrayList<String>(orList<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.