the code is as follows
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("hello");
list.add("alex");
list.add("front");
BiConsumer<List<String>, String> v = List::add;
System.out.println(v == null);
v.accept(list, "ddd");
System.out.println(list);
}
IDE does not report an error for IDEA, and is running normally.
my question is why the following sentence is correct:
BiConsumer<List<String>, String> v = List::add;
List is an interface, the add method has only a declaration and no specific implementation, and its front obviously does not match the accept of the BiConsumer interface.
BiConsumer interface definition:
@FunctionalInterface
public interface BiConsumer<T, U> {
void accept(T t, U u);
default BiConsumer<T, U> andThen(BiConsumer<? super T, ? super U> after) {
Objects.requireNonNull(after);
return (l, r) -> {
accept(l, r);
after.accept(l, r);
};
}
}
method signature of List::add:
boolean add(E e);
-
in addition, if I remove the generics, I will report an error as follows:
BiConsumer v = List::add;
Why is that?