美文网首页码农的世界程序员
跟 JDK 学英语(7)- Iterable

跟 JDK 学英语(7)- Iterable

作者: 码语生活 | 来源:发表于2018-11-01 21:52 被阅读1次

一、原文与翻译

public interface Iterable<T>

Implementing this interface allows an object to be the target of the "for-each loop" statement. See For-each Loop

实现了该接口后,可以在这个对象上使用 for-each 循环语句。

Since: 1.5

自:1.5

default void forEach(Consumer<? super T> action)

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of iteration (if an iteration order is specified). Exceptions thrown by the action are relayed to the caller.

对于 Iterable 对象的每一个元素均执行传入的动作,直到所有的元素被处理完或者是动作抛出了异常。除非实现类有具体实现,否则会按照迭代顺序执行动作(如果有定义迭代顺序的话)。被动作抛出的异常会传递给方法调用者。

Implementation Requirements:
The default implementation behaves as if:
for (T t : this) action.accept(t);

实现需要:
默认的实现需要类似如下语句执行:
for (T t : this) action.accept(t);

default Spliterator<T> spliterator()
Creates a Spliterator over the elements described by this Iterable.

在这个 Iterable 描述的元素上创建一个 Spliterator 对象。

Implementation Requirements:
The default implementation creates an early-binding spliterator from the iterable's Iterator. The spliterator inherits the fail-fast properties of the iterable's iterator.

实现需求:
默认的实现从 iterable 的迭代器中创建了一个早期绑定的切割器。该切割器继承了迭代器的快速失败属性。

Implementation Note:
The default implementation should usually be overridden. The spliterator returned by the default implementation has poor splitting capabilities, is unsized, and does not report any spliterator characteristics. Implementing classes can nearly always provide a better implementation.

实现注意:
默认的实现通常应该被覆写。从默认的实现返回的切割器有较少的切割能力,不能重新分配大小,也不报告任何切割器的特性。实现了该接口的类常常可以提供更好的实现。

二、词汇学习

perform: 执行,实现
iteration: 迭代
relay: 传播,中继
accept: 接受
inherit: 继承

三、句子分析

The spliterator returned by the default implementation has poor splitting capabilities, is unsized, and does not report any spliterator characteristics.

本包的主语是 spliterator ,然后有三个谓语动词修饰:has, is, does.

四、技术要点

实现了 Iterable 接口的类,可以使用 for-each 语句来迭代每一个元素。

微信公众号.jpg

相关文章

网友评论

    本文标题:跟 JDK 学英语(7)- Iterable

    本文链接:https://www.haomeiwen.com/subject/pwhfxqtx.html