From Function<T, Boolean> to t Predicate<T> - What is preferred ?

Boaz Nahum boaznahum at gmail.com
Mon Dec 31 10:50:02 PST 2012


So Predicate<T> is not Function<T, Boolean>

class Iters {

    static boolean beginWithA(String s) {
        return s.startsWith("a");
    }
}

Function<String, Boolean> map = Iters::beginWithA;

Should we

          Predicate<String> filter = Iters::beginWithA;

Or this is not too bad:
Predicate<String> filter = map::apply

Will optimization come to rescue us in the second case

Thanks
Boaz


More information about the lambda-dev mailing list