Remember, lambda expressions are anonymous methods and they remove a lot of ceremonial code around the main instruction that the code is conveying.
Now consider the case where a lambda expression is simply calling a method that already exists, and nothing more. In that case, we can simply things even further.
If, say, you have a class SomeClass that has a method someMethod(int a, int b) then the lambda expression
(a, b) -> SomeClass.someMethod(a, b)
can be written using a method reference as just
Again, don’t confuse unfamiliar with more complicated. With practice you’ll see when lambda expressions and method references get the point of your code across better than the old way of doing things would.
There’s a little bit more to it, though. There are 4 different usages of method references.
|Reference to a static method||
|Reference to an instance method of a particular object||
|Reference to an instance method of an arbitrary object of a particular type||
|Reference to a constructor||
If you’d like to see more examples of method references check out the official docs here.