public class SomeClass{
public static int someFunction(int a) {
return a;
}
public static void main(String[] args) {
Consumer<Integer> c = SomeClass::someFunction;
}
}
I'm not getting why: Consumer<Integer> c = SomeClass::someFunction;
is not producing a compilation error, since the function someFunction is a method with return value, and Consumer is representing methods with no return value
SomeClass::someFunction
as a consumer. It will happily consume an integer. You just won't be able to capture the return value. Why should it be a compile error?List.add()
) that many people don't even realize returns a value; if you couldn't convertlist::add
to aConsumer<T>
, that would be really irritating.)