Ho appena iniziato a utilizzare Java 8 e mi chiedo se esiste un modo per scrivere un metodo che restituisca uno Function
?Return Lambda dal metodo in Java 8?
In questo momento ho metodo come di seguito:
Function<Integer, String> getMyFunction() {
return new Function<Integer, String>() {
@Override public String apply(Integer integer) {
return "Hello, world!"
}
}
}
C'è un modo di scrivere che più succintamente in Java 8? Speravo che questo avrebbe funzionato, ma non è così:
Function<Integer, String> getMyFunction() {
return (it) -> { return "Hello, world: " + it }
}