yogesh doshi wrote:I just wanted Lamda Expression having more than one sentence.
The method defined in the functional interface Calc requires a parameter and a return value, both of type int. The method defined in the functional interface Calc1 doesn't require a parameter nor a return value. So either change the type of obj1 to Calc1 or make sure the lambda expression has a parameter and returns a value, for example
In Simple words Lambda expression is providing implementation for functional interface abstract method. Here public interface Calc is a functional interface. Its method is doCalculation. So your providing implementation for doCalculation. When you writing lambda expression for that method( I mean providing implementation), first you need to look at method declaration. Here doCalculation is taking one int type parameter, so you need to mention int type variable in left part of lambda expression or you can simply mention variable name. second thing , doCalculation return type is int. It may return some integer value.So you need to return some integer value in your right part of lambda expression.
Coming to your code error,
Please observe lambda expression implementation. You are not mentioned any parameter in left part of lambda expression and There is return statement at the end of right part of lambda expression. That's why you are getting compile time error.
Here you provided right implementation, So no error .