Why introduce an interface while it is already implemented on parents?

I see in many places, even in the Java kernel, that despite the implementation of the interface in the parent, the child classes explicitly implement the same interface.

As an example, this is an AbstractSet definition that implements Set.

 public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E> 

and HashSet extends AbstractSet.

 public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, java.io.Serializable 

why should we explicitly implement Set again? again the same template on LinkedHashSet that the HashSet continues.

 public class LinkedHashSet<E> extends HashSet<E> implements Set<E>, Cloneable, java.io.Serializable 

LinkedHashSet extends HashSet ,

HashSet implements Set<E> , Cloneable , java.io.Serializable

LinkedHashSet implicitly implements all interfaces, its parents are expanding. So why is this? I tried to figure it out, but I could not find the reason for this. even if it’s for readability, why does it not explicitly implement Collection?

More readable if we remove this unnecessary keyword. Does anyone know the reason for this?

I saw some question in SOF about this, but I was not convinced that this is for better readability, if this is the reason why the Collection interface is not implemented either?

+5
source share

Source: https://habr.com/ru/post/1258886/


All Articles