Is there any benefit in implementing a interface in a subclass even though the superclass implements the same interface

前端 未结 6 1488
醉酒成梦
醉酒成梦 2021-01-12 05:29

When I was seeing the declaration of ArrayList

class ArrayList extends AbstractList
    implements List, RandomAccess         


        
6条回答
  •  不知归路
    2021-01-12 05:58

    Yes. It could've been omitted. But thus it is immediately visible that it is a List. Otherwise an extra click through the code / documentation would be required. I think that's the reason - clarity.

    And to add what Joeri Hendrickx commented - it is for the purpose of showing that ArrayList implements List. AbstractList in the whole picture is just for convenience and to reduce code duplication between List implementations.

    Reference: Why does ArrayList have "implements List"?

提交回复
热议问题