Let's say in the following example:
public class MyConsumer {
public void accept(int i) {}
public static void biAccept(MyConsumer mc, int i) {}
}
public class BiConsumerDemo {
public void accept(int i) { }
public static void biAccept(MyConsumer mc, int i) { }
private void testBiConsume() {
BiConsumer<MyConsumer, Integer> accumulator = (x, y) -> {};
accumulator = MyConsumer::accept;
accumulator = MyConsumer::biAccept;
accumulator = BiConsumerDemo::accept;
}
}
Why is a variable accumulatorthat is BiConsumer, which requires a function to accept 2 parameters, can be assigned with MyConsumer::acceptwhen this method accepts only one parameter?
What is the principle of this language in Java? If there is a term for it, what is it?
source
share