Java. Best procedure for de-serializing a Java generic object?

What is the best procedure for storing and retrieving, using native Java serialization, shared objects such as ArrayList<String>?

Edit: clarify. When I serialize an object of type ArrayList<String>I would like to de-serialize an object of the same type. However, I do not know how to discard this common object without causing a warning.

+3
source share
2 answers

I think I understand this question, although it could be said less vaguely. When you deserialize, you can use for raw, ArrayListand as long as it doesn't throw away ClassCastException, you know that you have this part; but if you add more ArrayList<String>(or List<String>), you will receive a warning that this is unsafe. A collection can contain integers, and only this tide will not catch it.

The usual best course of action is simply to fully align your serialization and deserialization code with each other and suppress the warnings that produce the result.

+5
source

, . , -, , , , .

+1

Source: https://habr.com/ru/post/1749654/


All Articles