I am not sure what exactly is confusing you so here is some other way how you can look at your example.
J j = Test::foo;
can be rewritten as
J j = () -> Test.foo();
since it provides body to m()
method from J
functional interface and that method doesn't require any arguments (which is why it starts with () ->
).
But that can be seen as shorter version of
J j = new J(){
public void m(){
Test.foo(); //correct despite `foo` returning value
}
};
which is correct, because Java allows us to ignore returned value of called method like in case of List#add(E element) which returns boolean
value, but we still are allowed to write code like list.add(1)
without having to handle returned value.