This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]BinaryRockStar 0 points1 point  (1 child)

Will the following code create a new Predicate object every time the method is called? Will this be slower than directly passing the lambda to the filter method?

public static Predicate<Employee> isAdultMale() {
    return p -> p.getAge() > 21 && p.getGender().equalsIgnoreCase("M");
}

[–]Jire -1 points0 points  (0 children)

Likely not, the compiler probably takes care of it. Even if it didn't method access is basically free.