I am having a tough time understanding how lambdas work. I understood lambdas are methods without names that can be passed around like a variable.
In the above code,
check( (h,k) -> h>1,5); // line A
Can anyone explain how is this passed and how it works ?In check method "i" has got 5 as value but Climb "ex" got some address. I thought the type should be boolean as h>1 should return a boolean value. I am not getting how lambdas work. Each example has something new
Your explanation in the first link you posted was really helpful. I still need wants these things to be clear
* Lamdas are essentially an object on which abstract methods of the functional interface are invoked right?
In the below example, I am trying to do with lambdas and without lambdas comparison.
I have commented without lambda code. According to my understanding, above code should work but it is throwing an error in line B saying there are unimplemented methods. what is wrong in my understanding?
Chivid Ram wrote:* Lamdas are essentially an object on which abstract methods of the functional interface are invoked right?
Almost. Lambdas are expressions that return something that looks like an object on which methods of the functional interface can be invoked. The expression part is important, because no functional objects are created until the expression is actually evaluated.
Probably you made some kind of mistake in overriding the method of the Climb1 interface because there's no restriction that a class can't implement a functional interface.
Ya .. In the previous code, I had commented interface implementation. If I have to implement abstract method then I can simply create the object of that class and call the method. what's the need of Lamdas here?