Java的:重写方法不抛出“java.lang.Throwable中的”

问题描述 投票:0回答:2

我得到以下编译时错误

call(play.mvc.Http.Context) in actions.Headers cannot override call(play.mvc.Http.Context) in play.mvc.Action
[error]   overridden method does not throw java.lang.Exception
[error]        public CompletionStage<Result> call(final Http.Context ctx) throws Throwable {

这里是代码:

public CompletionStage<Result> call(final Http.Context ctx) throws Throwable {
           ctx.response().setHeader("Access-Control-Allow-Origin", "*");
           ctx.response().setHeader("Allow", "*");
           ctx.response().setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
           ctx.response().setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Referer, User-Agent, token");
           ctx.response().setHeader("Access-Control-Expose-Headers", "Origin, X-Requested-With, Content-Type, Accept, Referer, User-Agent, token");

           return (CompletionStage<Result>) delegate.call(ctx);
       }

我现在用的打法framework 2.6

java playframework completion-stage
2个回答
2
投票

根据游戏框架2.6在集体诉讼的方法调用没有抛出Throwable的了,所以你的方法必须这样做,太的documentation


1
投票

只是删除从方法声明[抛出的Throwable。

© www.soinside.com 2019 - 2024. All rights reserved.