Ramya Subraamanian wrote:Why cant I pass a MyLambdaExample1 object in line1 . Compiler says, type Object is expected. MyLambdaExample1 is also an Object, right.
Ramya Subraamanian wrote:Its difficult to relate this to predicates, cos they seem very complicated. But I guess, I will have to remember it this way.
Ramya Subraamanian wrote:Thats using Anonymous inner class. we cannot instantiate the Predicate interface.We are just referring to the object that implements the interface , through the inner class and also overriding the test method.now its clear.
Ramya Subraamanian wrote:There was another doubt I had...how are we using the Predicate interface, test method in our class without implementing it. The answer should be, we are actually creating an anonymous inner class that implements the Predicate interface and overriding it in the lambda expression.
Ramya Subraamanian wrote:how are we using the Predicate interface, test method in our class without implementing it. The answer should be, we are actually creating an anonymous inner class that implements the Predicate interface and overriding it in the lambda expression.
That's why you can write the lambda expression: the compiler knows everything about the interface. Because the compiler knows the type of the parameter(s) of the method, you can write a lambda expression without even mentioning the parameter type
Consider Paul's rocket mass heater. |