これは理論上の問題であり、具体的な応用はありません。
私は触れない次の方法を持っています。(可能であれば) として使用できBiConsumer
ます。
void doSmallThing(A a, B b) {
// do something with a and b.
}
void doBigThing(List<A> as, B b) {
// What to do?
}
一定にas
保ちながら繰り返し使用するにはどうすればよいですか?b
this::doSmallThing
doBigThing
もちろん、以下は機能しません。
void doBigThing(List<A> as, B b) {
as.stream()
.forEach(this::doSmallThing);
}
以下はうまく機能し、実際に私が毎日使用しているものです。
void doBigThing(List<A> as, B b) {
as.stream()
.forEach(a -> doSmallThing(a, b));
}
以下もうまくいきますが、もう少しトリッキーです。
Consumer<A> doSmallThingWithFixedB(B b) {
return (a) -> doSmallThing(a, b);
}
void doBigThing(List<A> as, B b) {
as.stream()
.forEach(doSmallThingWithFixedB(b))
}
しかし、これらのソリューションのすべてがケースの単純さを実現しているわけではありませんConsumer
。それで、のために存在する単純なものはありBiConsumer
ますか?