我使用 Android Studio 的 Kotlin 插件将我的 Java 类转换为 Kotlin。问题是它仍然不是 Kotlin 风格。我想改用 Kotlin 数据类。但是,每当我使用主要和次要构造函数创建它时,它都不起作用。在我的情况下,正确的 DATA 类实现是什么?
class Task {
@SerializedName("_id")
var id: String? = null
@SerializedName("text")
var taskTitle: String? = null
@SerializedName("completed")
var isCompleted: Boolean? = null
constructor(taskTitle: String) {
this.taskTitle = taskTitle
}
constructor(taskTitle: String, completed: Boolean?) {
this.taskTitle = taskTitle
this.isCompleted = completed
}
constructor(id: String, taskTitle: String, isCompleted: Boolean?) {
this.id = id
this.taskTitle = taskTitle
this.isCompleted = isCompleted
}
}