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.)
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.)
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.
BD is correct. As A & C are just bad syntax.
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 '()'
b and D are correct, other options are bad sintax
B and D are correct because method reference is used only for reference method and constructor not for performing comparison