In Java library, what is the reason that the Collection interface doesn’t extend Cloneable and Serializable interfaces?
In Java library, what is the reason that the Collection interface doesn’t extend Cloneable
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Collectionis an interface that specifies a group of objects known as elements. The details of how the group of elements is maintained is left up to the concrete implementations ofCollection. For example, someCollectionimplementations likeListallow duplicate elements whereas other implementations likeSetdon’t. A lot of theCollectionimplementations have a publicclonemethod. However, it does’t really make sense to include it in all implementations ofCollection. This is becauseCollectionis an abstract representation. What matters is the implementation. The semantics and the implications of either cloning or serializing come into play when dealing with the actual implementation; that is, the concrete implementation should decide how it should be cloned or serialized, or even if it can be cloned or serialized. In some cases, depending on what the actual backing-implementation is, cloning and serialization may not make much sense. So mandating cloning and serialization in all implementations is actually less flexible and more restrictive. The specific implementation should make the decision as to whether it can be cloned or serialized.Here’s an explanation from Oracle’s documentation: