Play 2.5 Errors with Java 8 - 错误的类型参数和 lambda 表达式的数量错误
Play 2.5 Errors with Java 8 - wrong number of type arguments and lambda expression not expected here error
我正在尝试从 Play 2.4 升级到 Play 2.5。使用 Replaced F.Promise with Java 8's CompletionStage 中的指南,我将 F.Promise
、map
和 flatMap
替换为之前 link 中建议的替换(下面反映了更改片段) .
public CompletionStage<Result> parallel() {
final long start = System.currentTimeMillis();
final CompletionStage<WSResponse, Long> getLatency = resp -> System.currentTimeMillis() - start;
CompletionStage<Long> googleLatency = WS.url("http://google.com").get().thenApplyAsync(getLatency);
CompletionStage<Long> yahooLatency = WS.url("http://yahoo.com").get().thenApplyAsync(getLatency);
return googleLatency.thenComposeAsync(googleResponseTime ->
yahooLatency.thenApplyAsync(yahooResponseTime ->
ok(format("Google response time: %d; Yahoo response time: %d",
googleResponseTime, yahooResponseTime)))
);
}
在 运行 ./activator clean dist
之后,我收到以下错误:
[error] /Play-2-JS-2.5/app/controllers/Java8Controller.java:74: wrong number of type arguments; required 1
[error] CompletionStage
[error] /Play-2-JS-2.5/app/controllers/Java8Controller.java:74: lambda expression not expected here
[error] resp -> System.currentTimeMillis() - start
出于某种原因,它认为 CompletionStage<WSResponse, Long> getLatency
部分中应该只有一个而不是两个,并且由于某种原因它不喜欢 lambda 表达式,即使新 api 之前的语法也是如此替换在 Play 2.4 中成功运行。
我尝试切换回 https://github.com/btgrant-76/Play-2-Java-Scala-Java-8-Async-Comparison/blob/6a85cf31cfb804ef20bacf8e14d30ce46cc9307c/app/controllers/Java8Controller.java#L71-L83 中显示的旧调用,但它并没有提供任何更好的结果。谷歌搜索和搜索了一段时间,但不确定如何解决这个问题。任何可能的例子的建议将不胜感激。
替换
final CompletionStage<WSResponse, Long> getLatency = resp ->
System.currentTimeMillis() - start;
和
final Function<WSResponse, Long> getLatency = resp -> System.currentTimeMillis() - start;
因为 thenApplyAsync
接口中的方法 CompletionStage
接受 java.util.Function
希望这对您有所帮助。
祝你好运
我正在尝试从 Play 2.4 升级到 Play 2.5。使用 Replaced F.Promise with Java 8's CompletionStage 中的指南,我将 F.Promise
、map
和 flatMap
替换为之前 link 中建议的替换(下面反映了更改片段) .
public CompletionStage<Result> parallel() {
final long start = System.currentTimeMillis();
final CompletionStage<WSResponse, Long> getLatency = resp -> System.currentTimeMillis() - start;
CompletionStage<Long> googleLatency = WS.url("http://google.com").get().thenApplyAsync(getLatency);
CompletionStage<Long> yahooLatency = WS.url("http://yahoo.com").get().thenApplyAsync(getLatency);
return googleLatency.thenComposeAsync(googleResponseTime ->
yahooLatency.thenApplyAsync(yahooResponseTime ->
ok(format("Google response time: %d; Yahoo response time: %d",
googleResponseTime, yahooResponseTime)))
);
}
在 运行 ./activator clean dist
之后,我收到以下错误:
[error] /Play-2-JS-2.5/app/controllers/Java8Controller.java:74: wrong number of type arguments; required 1 [error] CompletionStage [error] /Play-2-JS-2.5/app/controllers/Java8Controller.java:74: lambda expression not expected here [error] resp -> System.currentTimeMillis() - start
出于某种原因,它认为 CompletionStage<WSResponse, Long> getLatency
部分中应该只有一个而不是两个,并且由于某种原因它不喜欢 lambda 表达式,即使新 api 之前的语法也是如此替换在 Play 2.4 中成功运行。
我尝试切换回 https://github.com/btgrant-76/Play-2-Java-Scala-Java-8-Async-Comparison/blob/6a85cf31cfb804ef20bacf8e14d30ce46cc9307c/app/controllers/Java8Controller.java#L71-L83 中显示的旧调用,但它并没有提供任何更好的结果。谷歌搜索和搜索了一段时间,但不确定如何解决这个问题。任何可能的例子的建议将不胜感激。
替换
final CompletionStage<WSResponse, Long> getLatency = resp ->
System.currentTimeMillis() - start;
和
final Function<WSResponse, Long> getLatency = resp -> System.currentTimeMillis() - start;
因为 thenApplyAsync
接口中的方法 CompletionStage
接受 java.util.Function
希望这对您有所帮助。
祝你好运