I don't understand why this code compiles without error or warning:
import java.util.ArrayList;
import java.util.List;
class A {}
interface I {
void methodI();
}
public class B {
public void test() {
List<I> l = new ArrayList<>();
l.add(A::new);
}
}
After all, A::new
should be a lambda (as shown when I print l.get(0) which gives B$$Lambda$/1/...
), so I don't see why it could fit in a list of the I interface.
(I'm using Java 8, but also tested with Java 10)