According to the Java Tutorial on Method References:
Sometimes... a lambda expression does nothing but call an existing method. In those cases, 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.
Do method references skip the overhead of the lambda wrapper? Might they in the future?
Despite Oracle's claims, I find the lambda syntax easier-to-read than the method reference short-hand. Plus, you can wrap any function in a lambda. The method reference syntax won't work on methods that return void, take or return primitive arrays, or throw checked exceptions.
If there's no performance penalty for doing so, I'm tempted to turn off the warning in my IDE and use the lambda syntax consistently without sprinkling the occasional method reference into my code.
Aucun commentaire:
Enregistrer un commentaire