Method iterator() declared in java.util.Collection and in java.lang.Iterable, its superinterface?

前端 未结 1 1583
孤城傲影
孤城傲影 2020-12-10 15:28

Can somebody explain to me why is the method Iterator iterator(); defined in java.util.Collection? Collection already extends java.l

相关标签:
1条回答
  • 2020-12-10 16:30

    The Collection interface was introduced in Java 1.2 with the Collections API. The iterator method was present then. However, the Iterable interface wasn't introduced until Java 1.5. The reason that Collection explicitly defines iterator is because it predates Iterable. The idea of a Collection returning an Iterator predates the idea of Iterable.

    0 讨论(0)
提交回复
热议问题