I\'ve just started working with Java 8 and I\'m struggling with this code snippet:
paramsValues[idx++] = new ReplyMessage() {
@Override
If ReplyMessage
is a functional interface, you could do
paramsValues[idx++] = reply -> message.reply(reply);
Here's a full example with stub implementations of the other classes in your question:
// Stub classes
class JsonObject { }
@FunctionalInterface
interface ReplyMessage {
void reply(T jo);
}
class LambdaDemo {
public static void main(String args[]) {
// Dummy variables
ReplyMessage message = new ReplyMessage() {
public void reply(JsonObject jo) {}
};
ReplyMessage[] paramsValues = new ReplyMessage[5];
int idx = 0;
// Your code, lambdafied
paramsValues[idx++] = reply -> message.reply(reply);
// Or,
// paramsValues[idx++] = message::reply;
// But then you could perhaps do with just ...
// paramsValues[idx++] = message;
}
}