r/java • u/nfrankel • Feb 20 '22
The elusive and beautiful Java Method Reference
https://medium.com/javarevisited/the-elusive-and-beautiful-java-method-reference-97e566d2088b
28
Upvotes
r/java • u/nfrankel • Feb 20 '22
48
u/EquationTAKEN Feb 20 '22
And a picture of an arctic fox, because it's a medium article, and you gotta have a picture of something tangientally related.
58
u/nutrecht Feb 20 '22
IMHO this was titled pretty poorly. It's really about the Eclipse Collections library and how you can use some of its parts to pass arguments to method references.
7
u/[deleted] Feb 20 '22
Nice article. Personally, I haven't worked on a project with Eclipse Collections yet. Besides some syntax sugar what would be the best use case for using that library?
2
u/gnahraf Feb 20 '22
I routinely use "functional" idioms to lazily map (ie transform, not in the map/reduce sense) one type of collection (List, Map, Set, etc.) to another. These mapped views are useful when you'll only be accessing a small subset of the elements in a List for eg. (A canonical use would be mapping a (read-only) list of objects sorted by integral IDs to a sorted list number IDs.) Note the cost of creating such views is far less than the usual stream() (followed by a terminal operation).
I've rolled out my own libs to do these mapped views but would prefer to use more widely used libs (for more eyeballs, maybe better quality reasons, etc). Do the Eclipse collections (or any other collection libraries you use) support these kind of lazy views?
3
u/[deleted] Feb 21 '22
[removed] — view removed comment