Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 30

Given a Member class with fields for name and yearsMembership, including getters and setters and a print method, and a list of clubMembers members:

Which two Stream methods can be changed to use method references? (Choose two.)

    Correct Answer: B, D

    Using method references can make the code cleaner and more readable. The method reference 'testName::compareToIgnoreCase' can be used in place of '.map(m -> testName.compareToIgnoreCase(m))' since it matches the functional interface of the map method. Similarly, 'Member::print' can be used in place of '.peek(m -> m.print())' as it directly refers to the print method of the Member class without the need for a lambda. The other options involve inappropriate syntax or incorrect usage of method references.

Discussion
[Removed]Options: BD

BD is correct. As A & C are just bad syntax.

rami_mlaielOptions: BD

B & D are correct. A : .filter(Integer::equals(0)); You cannot pass parameter when calling through reference C: .filter(Member::getYearsMembership() >= testMembershipLength); You cannot call method reference with '()'

d7bb0b2Options: BD

b and D are correct, other options are bad sintax

Mukes877Options: BD

B and D are correct because method reference is used only for reference method and constructor not for performing comparison