3

尝试编译时出现此错误:

Iterables 类型中的方法filter(Iterable<T>, Predicate<? super T>)不适用于参数 ( Iterator<PeopleSoftBalance>, ColumnLikePredicate<PeopleSoftBalance>)

这是 ColumnLikePredicate 类信号:

public class ColumnLikePredicate<T extends RowModel> implements Predicate<T>

我究竟做错了什么?

4

3 回答 3

14

听起来您正在将 an 传递Iterator给需要Iterable.

迭代器

集合上的迭代器

可迭代

实现这个接口允许一个对象成为“foreach”语句的目标。

Iterator是一个可用于迭代(不同)集合的对象。Iterable是一个可以迭代的对象。

我猜你有某种,collection你正在调用类似的东西Iterables.filter(collection.iterator(), predicate)。该类Iterables希望您传递 Iterable 本身,例如:

Iterables.filter(collection, predicate)
于 2010-08-11T02:26:39.233 回答
3

请注意,Guava 包括Iterators.filter()Iterables.filter()方法。调用第一个方法过滤Iterator,调用第二个方法过滤Iterable。

于 2010-08-12T02:09:32.620 回答
0

PeopleSoftBalance 是否扩展 RowModel ?

于 2010-08-11T02:25:18.740 回答