Cloneable and serializable reasons are not implemented in Java collection classes
Inexplicable to be asked such a question, also can not answer, record, why the Java Collection class does not implement cloneable and serializable interface.
1. Thecloneable interface function is to copy the property value of one object to another object, rather than a reference to the object.
2.Serializable interface function (this wordy)
2.1 Use of serialization
1. Sometimes, if you want an object to persist (save to disk), or to make a remote object call, use serialization to achieve these effects.
We have to implement the serializable interface for all classes that support persistent storage, and also to deserialize when reading.
2. For the JVM, the persisted class must have a tag that implements the serializable interface, which is associated with Serialversionuid, which is in the deserialization session
Make sure to load the object with that class.
3. It is worthwhile to note that persisted data is present in the Java heap, and the static type of data exists in the method area and cannot be persisted. If you do not want to have a member variable
Persistent, variable preceded by transient keyword
4. Of course the serialized Serialversionuid This can also be customized
3. Back to the topic of this post, why does the collection class do not implement the above two interfaces?
In fact, it is not difficult to see that cloneable is a copy of the object, serialization is also for the operation of the object, the collection class is just a tool to manage the object, like the list can be a linear management object,
Set sets are able to weigh objects, and these collection classes are created for and for managing objects.
In fact, both interfaces are objects that are really objects, not management objects such as collection classes. This is semantically the Cloneable interface and serializable interface of the collection class.
The specific type implementation in the collection, rather than the collection class, should be implemented for serialization.
Assuming that the collection class implements both interfaces, if I want to generate a collection that does not need to be serialized and does not need a clone, then the collection class is enforced, which violates the design principle of the collection.
Ref: 50556966
Ref: 76461517
Cloneable and serializable reasons are not implemented in Java collection classes