About Question enthuware.ocpjp.v8.2.1880 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

About Question enthuware.ocpjp.v8.2.1880 :

Post by ramy6_1 »

Hello ,

What you mean by "Unlike most other functional interfaces, BiConsumer is expected to operate via side-effects." ?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1880 :

Post by admin »

This statement is from https://docs.oracle.com/javase/8/docs/a ... sumer.html

Not sure whether you understand the meaning of the term "side effects". But basically, what it means is that it when you apply a BiConsumer on two arguments, it may modify the arguments themselves. Thus, applying the same BiConsumer on the same two arguments second time may produce a result that is different from the first time.
For example, if you have a BiConsumer that adds second argument to the first one like this:
bf = (a, b)-> a.append(b);

If you use this function on the same two arguments second time, the resulting value of a will be different.

Another term for this is "idempotent". Any function that is idempotent can be applied any number of times and the result will be the same as the first time. BiConsumer is not supposed to be idempotent, as per the documentation.

HTH,
Paul.

nikitos
Posts: 21
Joined: Mon Oct 24, 2016 6:55 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1880 :

Post by nikitos »

Small mistake in explanation:
Predicate<T> has: boolean test(T t);
In explanation written Object instead of T. If we use withour generic - you are true:)

The same for Function<T,R>

Same for BiFunction and BiConsumer.

Or some another mean there?

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests