public class MethRefVsLambdaExpr {
public static void main(String[] args) {
//1. below compiles
Consumer<String> cs1 = MethRefVsLambdaExpr::objParamMeth;
//2. below gets compiler error:
//Lambda expression's parameter o is expected to be of type String
Consumer<String> cs2 = (Object o) ->{};
}
static void objParamMeth(Object o) {}
}
- Why does equivalent code (1) compile for method reference but not for lambda expression (2) ?
- Any supporting documentation from Oracle?