This does not apply to the static / non-stationary method, nor to generics, but only to the BiConsumer definition.
BiConsumer requires two parameters, so you need a lambda that requires two parameters and does not return any.
To fix this, use the instance method description :
FooQueue q = new FooQueue(); q.add(FooQueue::do1, new FooItem());
Do not confuse it with a reference to a static method. FooQueue::do1 is the syntax sugar for lambda:
(qInstance, item) -> qInstance.do1(item));
This approach only accepts methods from FooQueue .
Note that q:do1 not compatible with BiConsumer , as it converts to:
(item) -> q.do1(item)
Read more about Instance Method Link
Full example with different classes
public class App { public static void main(String[] args) { FooQueue q = new FooQueue(); FooQueue2 q2 = new FooQueue2(); q.add(FooQueue::do1, new FooItem());
source share