最佳答案
我在Kotlin数据类中声明了10+变量,我想为它创建一个空构造函数,就像我们通常在Java中做的那样。
数据类:
data class Activity(
var updated_on: String,
var tags: List<String>,
var description: String,
var user_id: List<Int>,
var status_id: Int,
var title: String,
var created_at: String,
var data: HashMap<*, *>,
var id: Int,
var counts: LinkedTreeMap<*, *>,
)
预期用途:
val activity = Activity();
activity.title = "New Computer"
sendToServer(activity)
但是data类要求在创建构造函数时传递所有参数。我们如何像Java POJO类构造函数那样简化它?
val activity = Activity(null,null,null,null,null,"New Computer",null,null,null,null)
sendToServer(activity)