Yorubaname/yorubaname-website

Refactoring Lambda to Method References

Closed this issue · 1 comments

Use lambda expressions to create anonymous methods is nice. But when a lambda does nothing beyond call an existing method it's often clearer to refer to the existing method by name.

Method references enable you to do this, they are compact, easy-to-read lambda expressions for methods that already have a name.

Lambda mode:

List<String> notFound = notFoundNames.stream()
                                                 .map(notFoundName -> notFoundName.getName())
                                                 .collect(Collectors.toList());

Method Reference mode:

List<String> notFound = notFoundNames.stream()
                                                 .map(NameEntry::getName)
                                                 .collect(Collectors.toList());

Solved #71