AbstractCollection
實現了接口Iterable
和Collection
。但是,Collection
是Iterable
的子接口。 AbstractCollection
實施Collection
難道不夠嗎?爲什麼AbstractCollection實現了Iterable和Collection?
1
A
回答
4
的Javadocs for AbstractCollection
可以被解釋爲AbstractCollection
直接實現Collection
和Iterable
。
所有已實現的接口:
可迭代,收集
然而,a quick look at the source code表明,它只直接實現Collection
。
public abstract class AbstractCollection<E> implements Collection<E> {
因此,Javadoc中必須被解釋爲說,類實現直接或間接給定的接口。正如您已經指出的那樣,不需要AbstractCollection
直接實現Iterable
,因爲它已經實現了Collection
。源代碼顯示它不直接實現Iterable
。它只需要AbstractCollection
就可以直接實現Collection
。
0
是的。這就夠了。但是,明確列出兩者都允許告訴(通過簡單的檢查)AbstractCollection
實現了Iterable
和Collection
(同樣,因爲它不是必須實現任一接口 - 但是任何具體的子類都會)。
相關問題
- 1. AbstractCollection爲什麼不實現iterator()?
- 2. 爲什麼AbstractCollection沒有實現equals()?
- 3. Junit實現了Iterable
- 4. Java中的Collection和AbstractCollection有什麼區別?
- 5. Iterable with size() - 在Iterable和Collection之間?
- 6. 實現Iterable
- 7. 爲什麼在Iterable中實現zipWithIndex而不是Traversable?
- 8. AbstractCollection的用途是什麼
- 9. 實現Iterable接口
- 10. 如何實現Iterable
- 11. AbstractCollection的toString()如何在Java中的Collection中打印Collection?
- 12. Java實現Iterable,每個和方法
- 13. 爲什麼Iterable <DeclarationMirror>不能轉換爲Iterable <MethodMirror>?
- 14. 爲什麼Collection接口有equals()和hashCode()?
- 15. Java中的Iterable的實現
- 16. 泛型類實現Iterable
- 17. Iterable&Iterator實現問題(JAVA)
- 18. Eiffel MAP上的Iterable實現?
- 19. 如何實現Iterable接口?
- 20. Java:WeakHashMap爲什麼實現Map,而AbstractMap已經實現了它?
- 21. 爲什麼發生字節溢出,它們實現了什麼?
- 22. 爲什麼不科特林陣列<T>實現Iterable <T>
- 23. 如何從Iterable/Collection創建TreeMultimap?
- 24. 的Java:如何實現`toArray`爲`Collection`
- 25. 實現java Collection接口的正確方法是什麼
- 26. 爲什麼Hashtable實現ICollection和IEnumerable?
- 27. 如何實現JObj Collection
- 28. 如何實現Collection對象
- 29. 這個shell測試實現了什麼
- 30. Shadow DOM讓我們實現了什麼?
有趣。我不知道javadoc是這麼做的。我只是假定這是源代碼的寫法。 –