在我的 POJO 中,我通常会像这样声明字段
class SampleModel {
var field1: String? = null
var field2: Int? = null
<more fields here>
}
如果我这样声明,我将需要检查该字段是否为空。
但如果是这样:
class SampleModel {
var field1 = ""
var field2 = 0
<more fields here>
}
我可以直接使用它。
使用哪个声明有关系吗?就像在内存、性能或其他方面的好习惯一样?
假设我有 100 个字段。然后我使用 Moshi 或 Gson 作为反序列化器。