answer: A
List
forEach
default void forEach(Consumer<? super T> action)
There is syntax error with parentheses and generic type.
it should be this way
Consumer function = f->{System.out.println(f);};
or
Consumer<String> function = f->{System.out.println(f);};
In fact, the above answers are all wrong
A seems correct, but the writing in lambda is wrong
If rewritten as
# Consumer function = s -> System.out.println(s);
to compile normally
NOTICE: A is the correct but consumer is bad implement in the option because explicit paramater for lambda is (String f)->... and the compiler expect Object, the correct is :
1- Consumer x = x -> System.out.print(x)
or:
2- Consumer<String> x = (String f) -> .....
o
3- Consumer<String> x= f -> sout...
Actually answer A is also incorrect. As Consumer is actually Consumer<Object> so it expects an Object rather than a String. It would've worked if it were: f -> System.out.println(f);
forEach() accepts a Consumer, so correct answer is A.
Consumer function = f -> System.out.println(f);
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
6 months agoGalen86
10 months, 3 weeks agod7bb0b2
1 year, 1 month agod7bb0b2
1 year ago[Removed]
1 year, 5 months agotmuralimanohar
1 year, 7 months agoStavok
1 year, 8 months agoMukes877
1 year, 8 months agoAnkit1010
1 year, 12 months ago