I\'ve just started working with Java 8 and I\'m struggling with this code snippet:
paramsValues[idx++] = new ReplyMessage() {
@Override
Lambda expressions are only possible with Functional Interfaces (Interfaces with only one method, such as Runnable or ActionEvent
)
If ReplyMessage
is a functional interface, you can do:
paramsValues[idx++] = reply -> message.reply(reply);
Lambda expressions are formed in this pattern: parameters that the method should take, then ->
then the method body
Here is the code of how ReplyMessage
interface should look like:
@FunctionalInterface
interface ReplyMessage {
void reply(T jo);
}
For more information, consider reading this.