I have a Stream<SomeClass> stream , while SomeClass has the boolean methods isFoo() and isBar() .
I want to check that all elements in the stream have both isFoo() and isBar() equal to true . I can check these conditions individually with SomeClass:isFoo and SomeClass::isBar lambdas.
But how would you combine these two lambdas with a logical operator like and / && ?
One obvious way is to write an extra lambda:
stream.allMatch(item -> item.isFoo() && item.isBar());
But I would like not to write extra lambda.
Another way is to pass Predicate<? super SomeClass> Predicate<? super SomeClass> :
stream.allMatch(((Predicate<? super SomeClass>) SomeClass::isFoo).and(SomeClass::isBar));
Is there a better way - without throws and explicit iambds?
source share