You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really appreciate your book for OCPj8. You did a great work !
As for chapter 9 in the question
A lambda expression can be used...
A. As a method argument
B. As a conditional expression in an if statement
C. In a return statement
D. In a throw statement
I'm not sure about "conditional expression in an if statement". It looks that we do can
use lambdas in a conditional expression as
It's just a method call. You use a lambda in an assignment expression to create an implementation of the interface, but you're not using the lambda expression directly as the condition of the if statement.
I was referring to something like this:
if ( (intrr) -> rr == 0 )
Which is wrong, a lambda expression doesn't evaluates to/return a boolean.
You can see a lambda expression as a shortcut for creating an anonymous class. Maybe a method from that anonymous class returns a boolean, but the class itself can't be used as the expression of an if statement.
But a lambda expression can be used in a return statement as long as the method returns the type the lambda expression represents:
By the way, in the answer explanation, I mention lambda expression can be used in "A ternary conditional expression". I don't mean the conditional expression, because it'd the same case. I mean this:
Hi,
I really appreciate your book for OCPj8. You did a great work !
As for chapter 9 in the question
A. As a method argument
B. As a conditional expression in an if statement
C. In a return statement
D. In a throw statement
I'm not sure about "conditional expression in an if statement". It looks that we do can
use lambdas in a conditional expression as
interface IBoo {
boolean b(int z);
}
. . .
IBoo ib = (int rr) -> rr == 0;
if ( ib.b(0) ){
System.out.println("zero");
}
Or I did not get some idea in the text ? I can not find a difference in application of lambdas between
return statement and if (condition).
Thanks, Iurii
The text was updated successfully, but these errors were encountered: