lambda - Java 8: Difference between method reference Bound Receiver and UnBound Receiver -


i trying use java 8 method references in code. there 4 typed of method references available.

  1. static method reference.
  2. instance method (bound receiver).
  3. instance method (unbound receiver).
  4. constructor reference.

with static method reference , constructor reference have no problem, instance method (bound receiver) , instance method (unbound receiver) confused me. in bound receiver use object reference variable calling method like:

objectref::instance method 

in unbound receiver use class name calling method like:

classname::instance method. 

i have following question:

  1. what need different types of method references instance methods?
  2. what difference between bound , unbound receiver method references?
  3. where use bound receiver , use unbound receiver?

i finding explanation of bound , unbound receiver java 8 language features books, still confused actual concept.

the idea of unbound receiver such string::length you’re referring method object will supplied 1 of parameters of lambda. example, lambda expression (string s) -> s.touppercase() can rewritten string::touppercase.

but bounded refers situation when you’re calling method in lambda external object exists. example, lambda expression () -> expensivetransaction.getvalue() can rewritten expensivetransaction::getvalue.

situations 3 different ways of method reference

(args) -> classname.staticmethod(args) can classname::staticmethod

(arg0, rest) -> arg0.instancemethod(rest) can classname::instancemethod (arg0 of type classname)

(args) -> expr.instancemethod(args) can expr::instancemethod

answer retired java 8 in action book


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -