Java 8 type inference error, assigning lambda expression to a variable of type Object

Viewed 285

Why is the java compiler complaining about the first statement, it's because the expression () -> "" doesn't have a definite type, i mean it could be a Supplier <String> or a custom functional interface type, etc ... ?

Object emptyStringBuilder = () -> ""; // causes compiler error

Object emptyStringBuilder = (Supplier<String>)() -> "";

Could you elaborate on the exact causes please ?

2 Answers
Related