使用 DatabaseReference.setValue() 存储 Class 真的需要 Getter 方法吗?

Are Getter Methods Really Needed for Class Stored Using DatabaseReference.setValue()?

DatabaseReference 的所有 setValue() 方法的 documentation 状态:

In addition, you can set instances of your own class into this location, provided they satisfy the following constraints:

  1. The class must have a default constructor that takes no arguments
  2. The class must define public getters for the properties to be assigned.

Properties without a public getter will be set to their default value when an instance is deserialized.

QuickStart 示例项目中定义的模型 类 没有定义 getter 方法。我的实验似乎表明它们实际上并不需要。我能够成功存储和检索 类 的实例,这些实例没有定义 getter 方法,只有 public 字段。文档是否正确?

这里是 Firebaser

适用于 Android 的 Firebase 数据库 SDK 将 serialize/deserialize 属性基于:

  • 类 JavaBean getters/setters
  • public 字段

我将添加一条注释,我们也应该记录第二种类型。