I am trying to use Java 8 method references in my code. There are four types of method references available.
- Static method reference.
- Instance Method (Bound receiver).
- Instance Method (UnBound receiver).
- Constructor reference.
With Static method reference
and Constructor reference
i have no problem, but Instance Method (Bound receiver)
and Instance Method (UnBound receiver)
really confused me. In Bound
receiver, we are using an Object reference variable for calling a method like:
objectRef::Instance Method
In UnBound
receiver we are using Class name for calling a method like:
ClassName::Instance Method.
I have the following question:
- What is the need for different types of method references for Instance Methods?
- What is the difference between
Bound
andUnbound
receiver method references? - Where should we use
Bound
receiver and where should we useUnbound
receiver?
I also found the explanation of Bound
and Unbound
receiver from Java 8 language features books, but was still confused with the actual concept.