Are there any reasons why specifying the argument type is required in Java 8 lambda syntax?
Pergunta
I have read http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-4.html and noticed that all the examples have argument type declared explicitly, even though it's already known from the interface-function declaration.
public interface FileFilter {
/** ... **/
boolean accept(File pathname);
}
FileFilter java = (File f) -> f.getName().endsWith(".java");
Can't we go with just
(f) -> f.getName().endsWith(".java"); ?
UPDATE: In the JSR-335 Draft, I have found that inferred-type parameters are most likely to be supported
(int x) -> x+1 // Single declared-type parameter
(int x) -> { return x+1; } // Single declared-type parameter
(x) -> x+1 // Single inferred-type parameter
x -> x+1 // Parens optional for single inferred-type case
Nenhuma solução correta
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow