I know that data class are like simple models in kotlin with getters and setter by default and are as simple this:
data class User(val name: String, val age:
Updated answer for data classes:
Yes you can, but you will need to delegate everything to the primary constructor
data class User(val name: String, val age: Int)
{
constructor(name: String): this(name, -1) {
}
constructor(age: Int): this("Anon", age) {
}
}
// Anon name: Anon
println("Anon name: " + User(30).name)
// No age: -1
println("No age: " + User("Name").age)
// Name: Name age: 20
val u = User("Name", 20)
println("Name: " + u.name + " age: " + u.age)
You can also set default values in your primary constructor as Alexey did.