Reputation: 1043
I want to use the function Predicate instead of the & operator. it means that I want that "Second Test is passed !!" be printed after the execution of my code.
How can I do it ?
public class BitwiseInclusiveAND{
public static void main(String[] args) {
final Predicate<String> condition1 = (Predicate<String>) (arg -> arg != null);
final Predicate<String> condition2 = (Predicate<String>) (arg -> {
System.out.println("Second Test is passed !!");
return arg.equals("Hello");
});
Predicate<String> equalsStrings
= condition1.and(condition2); // Here I want to execute the condition2 even if condition 1 = true
System.out.println(equalsStrings.test("Hello"));
}
}
Upvotes: 2
Views: 181
Reputation: 140494
Just implement the predicate yourself:
Predicate<String> or = s -> condition1.test(s) & condition2.test(s);
Replacing the &
with whatever other operator you might want.
Upvotes: 5