【发布时间】:2016-06-16 12:04:38
【问题描述】:
给定一个如下结构的类:
public class Section extends IterableWidgetTemplate<Item>{
private List<WebElement> items1;
// other non iterable methods
private int indexOf(final Item item) {
int i = Iterables.indexOf(this, new Predicate<Item>() {
. . .
});
return i;
}
其中Iterables 是 Guava com.google.common.collect.Iterables,根据其文档,它包含对 Iterable 类型的对象进行操作的静态实用程序方法。
现在在我上面描述的类中,this 作为可迭代对象传递给 private int indexOf() 方法。
问题:
- 我要在
this对象中迭代什么?我的假设是否正确,Iterables类将使用传递给它的对象中唯一可用的可迭代方法?所以在这种情况下,我们在this对象中包含了List<WebElement>变量。 - 如果 1. 的答案是“是”,如果
Section类有多个可迭代变量会怎样?其中哪一个将用于迭代?
【问题讨论】:
标签: java iterator guava iterable