Sudhir Singh Khanger
02/27/2021, 3:30 AM// generated by JsonToKotlinClass
data class JsonToKotlinClass(
val `data`: List<Data?>?
) {
data class Data(
val id: Int?
)
}
// generated by RoboPOJOGenerator
data class RoboPOJOGenerator(
val data: List<DataItem?>? = null
)
data class DataItem(
val id: Int? = null
)
fun main() {
val jsonToKotlinClassData: JsonToKotlinClass.Data = JsonToKotlinClass.Data(1)
val roboPOJOGeneratorData: DataItem = DataItem(1)
}
The former is generated by JsonToKotlinClass plugin and latter is generated by RoboPOJOGenerator. Which one would you prefer? Besides differences in syntax and how they are used are there other pros and cons of these two approaches.jbnizet
02/27/2021, 7:34 AMnanodeath
02/27/2021, 5:39 PMdata class Foo(val data: List<DataItem>)
or maybe
data class Foo(val data: List<DataItem> = emptyList())
there's still the question of whether the other type should be an inner class or not, but 1. doesn't really matter, and 2. it depends on whether that type is constructed exclusively by Foo
or not, IMO.Sudhir Singh Khanger
02/28/2021, 4:39 AMJsonToKotlinClass.Data
.jbnizet
02/28/2021, 9:44 AMSudhir Singh Khanger
02/28/2021, 1:12 PMnanodeath
02/28/2021, 2:49 PMinner
keyword to the, ahem, nested class, and then it can access instance state of the enclosing class. but if you don't, not really any differences.