Understanding Java-8 method references with examples
In my previous post , I described about Lamda expression and its usages. Now I am going to write about method references in Java 8. What is a method reference? As I described in my previous post , a lamda expression is an anonymous function. However, sometimes lamda expression is only calling an existing method. On the other hand, if the function code in the lamda expression is too complicated or has many lines, it makes sense to include it in a separate method. This is when method references comes in handy. Instead of writing a lamda expression, we can refer to an existing method. Based on the method type, there are 4 types of method reference syntax. Type Syntax Reference to a static method ContainingClass::staticMethodName Reference to an instance method of a particular object containingObject::instanceMethodName Reference to an instance method of an arbitrary object of a particular type ContainingType::methodName ...