适用于 Java 的 SDK 版本 1 和版本 2 之间的 fluent setter 方法差异 - AWS SDK for Java 2.x

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

适用于 Java 的 SDK 版本 1 和版本 2 之间的 fluent setter 方法差异

您可以在 DynamoDB 映射 API 的 V1 版以及自 2.30.29 版本开始的 V2 版中使用带 fluent setter 的 POJO。

例如,以下 POJO 通过 setName 方法返回一个 Customer 实例:

// V1 @DynamoDBTable(tableName ="Customer") public class Customer{ private String name; // Other attributes and methods not shown. public Customer setName(String name){ this.name = name; return this; } }

但是,如果您使用的是 2.30.29 之前的 V2 版本,则 setName 会返回 Customer 实例,其 name 值为 null

// V2 prior to version 2.30.29. @DynamoDbBean public class Customer{ private String name; // Other attributes and methods not shown. public Customer setName(String name){ this.name = name; return this; // Bug: returns this instance with a `name` value of `null`. } }
// Available in V2 since version 2.30.29. @DynamoDbBean public class Customer{ private String name; // Other attributes and methods not shown. public Customer setName(String name){ this.name = name; return this; // Returns this instance for method chaining with the `name` value set. } }