Method Reference Parameter allowed but equivalent Lambda Expression does not compile

Viewed 50
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) {}
}
  1. Why does equivalent code (1) compile for method reference but not for lambda expression (2) ?
  2. Any supporting documentation from Oracle?
0 Answers
Related