Every time a lambda taking an argument is created, an object is created.
This object is unique and makes it harder for the JIT compilation to
optimize the code.
By replacing lambdas with method references, we help the JIT better
understand our code, and reduce object creations* and garbage
collection.
Using method references also helps humans better understand the code,
and might even make compilation faster: the method, and where it lives,
is explicitely written: no need to guess it.
repoUpgraded.stream().map(n -> n.get()).collect(...);
Where does the get method come from? Hard to tell.
repoUpgraded.stream().map(NameKey::get).collect()
Same line of code, using a method reference. It is clear that the input
objects are NameKey-s, and we call the get method on them.
* This is technically wrong, as a pointer is created even when we use a
method reference, but it is at least smaller than the lambda
counterpart.
Change-Id: Ic85b1b593d42968f262d3afe49a2ad87a4b766b9