Saturday 1 June 2019

Why a collection doesn’t extend Cloneable or Serializable interfaces?


When you see the definition of Collection interface, it is defined like below.

public interface Collection<E> extends Iterable<E> {
    .....
    .....
}

As you see Collection interface doesn’t extend Cloneable or Serializable interface.

Why Collection interface doesn’t extend Cloneable or Serializable interfaces?
It is because, Collection is the root interface for all the collection classes (like ArrayList, LinkedList). If collection interface extends Cloneable/Serializable interfaces, then it is mandating all the concrete implementations of this interface to implement cloneable and serializable interfaces. To give freedom to concrete implementation classes, Collection interface don’t extended Cloneable or Serializable interfaces.



You may like

No comments:

Post a Comment