Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AWS SDK for java 1.7_Java_Amazon Web Services_Sdk - Fatal编程技术网

AWS SDK for java 1.7

AWS SDK for java 1.7,java,amazon-web-services,sdk,Java,Amazon Web Services,Sdk,我试图访问aws Web服务,这里有lambda表达式,但我的项目是java 7,所以我想将此代码转换为普通方法 final Unmarshaller<ApiGatewayResponse, JsonUnmarshallerContext> responseUnmarshaller = in -> { System.out.println(in.getHttpResponse()); return new ApiGatewa

我试图访问aws Web服务,这里有lambda表达式,但我的项目是java 7,所以我想将此代码转换为普通方法

   final Unmarshaller<ApiGatewayResponse, JsonUnmarshallerContext> responseUnmarshaller = in -> {
            System.out.println(in.getHttpResponse());
            return new ApiGatewayResponse(in.getHttpResponse());};
final Unmarshaller responseUnmarshaller=in->{
System.out.println(in.getHttpResponse());
返回新的ApiGatewayResponse(在.getHttpResponse());};

lambda表达式可以转换为匿名类或命名类

在您的示例中,您需要一个实现接口的类:

Unmarshaller<ApiGatewayResponse, JsonUnmarshallerContext>
所以我们可以创建匿名类+实例,如下所示:

public interface Unmarshaller<T, R> {
    public T unmarshall(R in) throws Exception;
}
Unmarshaller<ApiGatewayResponse, JsonUnmarshallerContext> responseUnmarshaller =
    new Unmarshaller<>() {
        public ApiGatewayResponse unmarshall(JsonUnmarshallerContext in) 
            throws Exception {
            return ...
        }
};

请注意,您的示例有些可疑之处。根据我正在查看的
ApiGatewayResponse
是一个抽象类,因此我们不能
new
它。但是你正在翻译的lambda(显然)是这样的


参考:


翻译这一点应该很简单。你尝试过什么?@StephenC谢谢,我是lambda的新手,我正在尝试初始化
JSONumarshallerContext
,但这是一个抽象类,所以我创建了一个自定义类来扩展JSONumarshallerContext。但它仍然返回空对象JSONumarshallerInstitanter JSONumarshallerContext=new JSONumarshallerInstitanter();最终解组器responseUnmarshaller=(解组器)新的ApiGatewayResponse(jsonUnmarshallerContext.getHttpResponse());而且。。。它有效吗?我的观点是,如果你让别人为你写代码,你不会学会如何为自己写代码。如果您想让资源了解lambdas,请从Oracle Java教程开始:@StephenC不,它不起作用,我在这里遗漏了什么吗?非常感谢您的回答,它起作用了。我会调查医生的。
            System.out.println(in.getHttpResponse());
            return new ApiGatewayResponse(in.getHttpResponse());