英文:
how return args works in Java 8?
问题
I'm new to Java8
Can anyone share what return args
is returning in below code snippet? How it looks like in Java 7 to understand what's actually happening?
public ApplicationRunner initializeConnection(
RsvpsWebSocketHandler rsvpsWebSocketHandler) {
return args -> {
WebSocketClient rsvpsSocketClient = new StandardWebSocketClient();
rsvpsSocketClient.doHandshake(
rsvpsWebSocketHandler, MEETUP_RSVPS_ENDPOINT);
};
}
英文:
I'm new to Java8
Can anyone share what return args
is returning in below code snippet ? How it looks like in Java 7 to understand what's actually happening ?
public ApplicationRunner initializeConnection(
RsvpsWebSocketHandler rsvpsWebSocketHandler) {
return args -> {
WebSocketClient rsvpsSocketClient = new StandardWebSocketClient();
rsvpsSocketClient.doHandshake(
rsvpsWebSocketHandler, MEETUP_RSVPS_ENDPOINT);
};
}
答案1
得分: 2
这是一个 lambda
,只是匿名类的简写初始化。在 Java 1.7
中,它会像这样:
return new ApplicationRunner() {
@Override
public void run(ApplicationArguments args) throws Exception {
WebSocketClient rsvpsSocketClient = new StandardWebSocketClient();
rsvpsSocketClient.doHandshake(rsvpsWebSocketHandler, MEETUP_RSVPS_ENDPOINT);
}
};
英文:
It's a lambda
, which is just a shorthand initialization of an anonymous class.
In Java 1.7
it would look like:
return new ApplicationRunner() {
@Override
public void run(ApplicationArguments args) throws Exception {
WebSocketClient rsvpsSocketClient = new StandardWebSocketClient();
rsvpsSocketClient.doHandshake(rsvpsWebSocketHandler, MEETUP_RSVPS_ENDPOINT);
}
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论