tags:

views:

97

answers:

3

I get this error when trying to compile:

The method filter(Iterable<T>, Predicate<? super T>) in the type Iterables is not applicable for the arguments (Iterator<PeopleSoftBalance>, ColumnLikePredicate<PeopleSoftBalance>)

Here is the ColumnLikePredicate class sig:

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

What am I doing wrong?

A: 

Does PeopleSoftBalance extend RowModel ?

Romain Hippeau
+10  A: 

Sounds like you are passing an Iterator to a method that expects an Iterable.

Iterator:

An iterator over a collection

Iterable:

Implementing this interface allows an object to be the target of the "foreach" statement.

Iterator is an object that can be used to iterate over a (different) collection. Iterable is an object that can be iterated over.

I would guess that you have some sort of collection and you are calling something like Iterables.filter(collection.iterator(), predicate). The Iterables class wants you to pass the Iterable itself, like:

Iterables.filter(collection, predicate)
matt b
LOL, I gues I wasn't reading it.
arinte
+2  A: 

Note that Guava includes both Iterators.filter() and Iterables.filter() methods. Call the first method to filter an Iterator and the second method to filter an Iterable.

Jared Levy