JAVA源码阅读之----Iterable接口(1)

使用JAVA语言编程,集合是必须要掌握的.
作为集合的根接口.

今日计划阅读Iterable接口的源码.

/**
 * Implementing this interface allows an object to be the target of
 * the "foreach" statement.
 *
 * @param <T> the type of elements returned by the iterator
 *
 * @since 1.5
 */
public interface Iterable<T>

该接口仅含一个方法
通过注释,可以了解该接口的作用.
实现这个接口便允许该对象声明为”foreach”的目标
也就是说,如果你自己编写了一个类实现了该接口,那么你就可以使用
foreach来遍历你写的集合对象

下面我们看看它定义的方法

    /**
     * Returns an iterator over a set of elements of type T.
     *
     * @return an Iterator.
     */
    Iterator<T> iterator();

注释:返回一组T类型元素的迭代器

猜你喜欢

转载自blog.csdn.net/qq_27515289/article/details/80183239