java - Why does List interface extend Collection interface? -
the collection interface has multiple methods. list interface extends collection interface. declares same methods collection interface? why so?
for example
interface collection extends iterable { public abstract int size(); public abstract boolean isempty(); public abstract boolean contains(java.lang.object); public abstract java.util.iterator<e> iterator(); public abstract java.lang.object[] toarray(); public abstract <t extends java/lang/object> t[] toarray(t[]); public abstract boolean add(e); public abstract boolean remove(java.lang.object); public abstract boolean containsall(java.util.collection<?>); public abstract boolean addall(java.util.collection<? extends e>); public abstract boolean removeall(java.util.collection<?>); public abstract boolean retainall(java.util.collection<?>); public abstract void clear(); public abstract boolean equals(java.lang.object); public abstract int hashcode(); }
and same methods present in list interface:
public interface list extends collection { public abstract int size(); public abstract boolean isempty(); public abstract boolean contains(java.lang.object); public abstract java.util.iterator<e> iterator(); public abstract java.lang.object[] toarray(); public abstract <t extends java/lang/object> t[] toarray(t[]); public abstract boolean add(e); public abstract boolean remove(java.lang.object); public abstract boolean containsall(java.util.collection<?>); public abstract boolean addall(java.util.collection<? extends e>); public abstract boolean removeall(java.util.collection<?>); public abstract boolean retainall(java.util.collection<?>); public abstract void clear(); public abstract boolean equals(java.lang.object); public abstract int hashcode(); }
is requirement write these methods again in list if extending collection interface?
they're re-written can documented, in order specify how list refines contract of these methods compared contract specified in collection interface.
for example, add()
method in list
documented specify element added end of list. can't specified in collection, since collection doesn't have beginning , end.
Comments
Post a Comment