My question is NOT regarding understanding the technical understanding of usage of Serializable interface. Those answers has already been explained [1] & [2] among others
My question is from syntactical point of view.
While watching the source code of Collection interface and its sub-interfaces I noticed most of the interfaces implements Cloneable
and java.io.Serializable
as shown below :
public class TreeSet<E> extends AbstractSet<E>
implements NavigableSet<E>, Cloneable, java.io.Serializable{
...
}
public class LinkedHashSet<E>
extends HashSet<E>
implements Set<E>, Cloneable, java.io.Serializable {
...
}
public class HashSet<E>
extends AbstractSet<E>
implements Set<E>, Cloneable, java.io.Serializable {
...
}
...and so on
I also noticed :
Collection
interface ,TreeSet
LinkedHashSet
etc. belongs topackage java.util;
Cloneable
interface belongs topackage java.lang;
Serializable
belongs topackage java.io;
Now my question is why are we adding the prefix java.io
before Serializable
(as shown above) and not import import java.io.Serializable;
as done in Collection interface.