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.

Was it helpful?

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top