I just noticed that Consumer
it has no method identity()
, for example java.util.function.Function
.
Yes, it would be just a hole into which the material could be poured, but at least it would be very clear that I didn’t just miss some kind of code in brackets.
Take this contrived example:
public void applyConsumerIfExists(String key, String param) {
Map<String, Consumer<String>> consumers = new HashMap<>();
consumers.put("a", MyClass::myConsumer);
Consumer<String> identity = input -> {};
consumers.getOrDefault(key, identity).accept(param);
consumers.getOrDefault(key, Consumer.identity()).accept(param);
}
Question
Why not Consumer
the hava a method identity
?
source
share