Tuesday, April 2, 2013

Re: Guava Iterators not working?


On Tuesday, April 2, 2013 10:49:55 AM UTC+2, membersound wrote:
Hi,

I'm trying to use Guava on the client side. But I'm getting errors for both Iterators and Iterables.
Whereas Iterables.filter() is annotated with @GwtIncompatible, but Iterators is not, so should be supported.

class Base;
class Foo extends Base;

List<Base> list;
Lists.newArrayList(Iterators.filter(list.iterator(), Foo.class));
Lists.newArrayList(Iterables.filter(list, Foo.class));

The method filter(Iterator<T>, Predicate<? super T>) in the type Iterators is not applicable for the arguments (Iterator<Base>, Class<Foo>)

filter(Iterator,Class) is not supported in GWT: http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/collect/Iterators.html#filter(java.util.Iterator, java.lang.Class)

You have to use filter(Iterator,Predicate) with a predicate that uses the "instanceof" operator:

x = Lists.newArrayList(Iterables.filter(list, new Predicate<Base>() {
  @Override
  public boolean apply(@Nullable Base input) {
    return input instanceof Foo;
  }
}));

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate