Why Collection does not extend Cloneable and Serializable interfaces

Why Collection does not extend Cloneable and Serializable interfaces

Various collection implementations including all collecitons provided by the JDK will have public clone method available but all collections don’t need clone method. Let’s say for example, pull data from database which is gigabyte of SQL data what would be mean to clone collection of this large and if somebody do this then this cause company to demand new disk ? Same scenario would be applied for serializable interface.
When we implement collection and do not know actual type of collection then it’s more flexible and would be less error prone to have client to decide what type of collection is desired from their side and create empty Collection of this type of collections and use addAll method to copy elements of original collection into new one.

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *