本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Fluent setters for Java SDK 版本 1 和版本 2 之间的区别
你可以在 V1 的 DynamoDB 映射 API 中使用 POJOs 流畅的设置器,也可以在 2.30.29 版本之后的 V2 中使用。
例如,以下 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. } }