Question

I read this article about guava Predicates

http://blog.solidcraft.eu/2010/10/googole-guava-v07-examples.html

note point Predicates / Functions

There are is written:

The invocation would be (returns boolean):

Predicates.in(users).apply(shouldNotHaveDigitsInLoginPredicate);

I cannot make so.

my IDE writes that method apply cannot be applyed to this type.

Please, help me.

Était-ce utile?

La solution

The blog entry does not make sense. Look at the API for Predicates:

Predicates.in(users) creates a Predicate of the generic type User, i.e. Predicate<User>. This predicate takes an argument of type User in its Predicate#apply(T) method. The class ShouldNotHaveDigitsInLoginPredicate implements Predicate<User> itself and is therefore not of type User. Therefore, your IDE warns you of a type mismatch.

What you can do is:

User user = getSomeUser();
Predicates.and(Predicates.in(users), new ShouldNotHaveDigitsInLoginPredicate())
    .apply(user);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top