Method and Constructor Reference
Method Reference
1.
Method Reference is an abbreviated syntax used with lambda expressions for invoking a method.
Double colon operator (::) is used to represent a method reference.
The syntax for the same is:
2. A method reference can be used to point the following types of methods:
Static method
Instance method
Constructors using new operator (TreeSet::new)
eg:
Constructor Reference
Instead of implementing the factory manually, we glue everything together via constructor reference.
We create a reference to the Person constructor via Person::new. The Java compiler automatically choose the right constructor by matching the signature of PersonFactory.create.
Last updated
Was this helpful?