This is just a theoretical question without specific application.
I have the following method, which I will not touch. It could (if possible at all) be used as BiConsumer.
void doSmallThing(A a, B b) {
}
void doBigThing(List<A> as, B b) {
}
How can I repeat on as, keeping constant band use this::doSmallThingin doBigThing?
Of course, the following does not work.
void doBigThing(List<A> as, B b) {
as.stream()
.forEach(this::doSmallThing);
}
The following works well and actually I use every day.
void doBigThing(List<A> as, B b) {
as.stream()
.forEach(a -> doSmallThing(a, b));
}
The following also works well, but a little more complicated.
Consumer<A> doSmallThingWithFixedB(B b) {
return (a) -> doSmallThing(a, b);
}
void doBigThing(List<A> as, B b) {
as.stream()
.forEach(doSmallThingWithFixedB(b))
}
But all these solutions do not get the simplicity of the case Consumer. So, is there something simple for BiConsumer?
source
share