即使超类实现相同的接口,在子类中实现接口也有任何好处 [英] Is there any benefit in implementing a interface in a subclass even though the superclass implements the same interface
问题描述
当我看到声明 ArrayList
class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
实现列表
接口,即使 ArrayList
的超类 AbstractList
实现了相同的列表
接口。
which implements List
interface even though ArrayList
's superclass AbstractList
implements the same List
interface.
abstract class AbstractList<E> extends AbstractCollection<E> implements List<E>
类似的声明可以在 HashMap
上找到, LinkedHashMap
声明也是。
Similar declarations can be found on HashMap
, LinkedHashMap
declarations also.
在 LinkedHashMap
的声明中,它仅实现 Map
接口而不是其他接口由超类 HashMap
实现的接口。
In the declaration of LinkedHashMap
, it implements Map
interface only and not the other interfaces implemented by its superclass HashMap
.
所以这样的声明可能有一些好处。
So there might be some benefits of having such declarations.
推荐答案
再次声明它们没有任何功能上的好处,它不会以任何方式影响行为。
There are no functional benefits to declaring them again, it does not affect the behavior in any way.
我想这只是为了更清楚地说明实现了哪些接口。
I guess it's only added to make it clearer which interfaces are implemented.
这篇关于即使超类实现相同的接口,在子类中实现接口也有任何好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!