문제

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.

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top