Is my interpretation of lambda expression in the context of c++ and Java is correct?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are not quite as same. Both create unnamed classes, but their similarity ends at that point.
In C++ you create a closure catching your local variables, optionally by reference. In Java, you just get a snapshot of the current local variable’s values (and those variables need to be “final”).
The purpose of anonymous inner classes is to extend another class or implement another interface ad-hoc. For that reason, anonymous inner classes can simulate the job of lambda expressions to some extend, for example by implementing the
Runnableinterface. Lambda expressions are specifically designed to be called and possibly modify the local variables in their environment.