Hello ,
What you mean by "Unlike most other functional interfaces, BiConsumer is expected to operate via side-effects." ?
About Question enthuware.ocpjp.v8.2.1880 :
Moderator: admin
-
- Posts: 124
- Joined: Wed Feb 12, 2014 2:44 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1880 :
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.
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.
-
- Posts: 21
- Joined: Mon Oct 24, 2016 6:55 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1880 :
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?
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?
Who is online
Users browsing this forum: No registered users and 6 guests