Page 1 of 1

About Question enthuware.ocajp.i.v8.2.1471 :

Posted: Sun Oct 28, 2018 12:49 am
by Celina
Why below is wrong
() -> true
I saw in the OCA study book, the parameter can be 0 and below is valid
print(()->true);

Re: About Question enthuware.ocajp.i.v8.2.1471 :

Posted: Sun Oct 28, 2018 2:41 am
by admin
Did you read the explanation for this option? It explains why this is invalid.
As per the problem statement, you have to pick only such a lambda expression that can be used to invoke a method that accepts a java.util.function.Predicate.

() -> true is a valid lambda expression as such but it cannot implement a Predicate.

Re: About Question enthuware.ocajp.i.v8.2.1471 :

Posted: Sun Oct 28, 2018 12:06 pm
by BespawlerC
admin wrote:
Sun Oct 28, 2018 2:41 am
Did you read the explanation for this option? It explains why this is invalid.
As per the problem statement, you have to pick only such a lambda expression that can be used to invoke a method that accepts a java.util.function.Predicate.

() -> true is a valid lambda expression as such but it cannot implement a Predicate.
Very nicely explained :thumbup:

Re: About Question enthuware.ocajp.i.v8.2.1471 :

Posted: Tue Oct 30, 2018 5:46 am
by Celina
admin wrote:
Sun Oct 28, 2018 2:41 am
Did you read the explanation for this option? It explains why this is invalid.
As per the problem statement, you have to pick only such a lambda expression that can be used to invoke a method that accepts a java.util.function.Predicate.

() -> true is a valid lambda expression as such but it cannot implement a Predicate.
Sorry English is my 2nd lanugage, just misunderstood the question , now I get it. Thanks.

Re: About Question enthuware.ocajp.i.v8.2.1471 :

Posted: Thu Apr 15, 2021 8:03 pm
by alfredo.zuloaga
This is also valid
Predicate predicate = x -> x == null;

Re: About Question enthuware.ocajp.i.v8.2.1471 :

Posted: Thu Apr 15, 2021 11:10 pm
by admin
Yes, it is valid. You may try writing a simple test program to check it out.