Creating DTOs POJOsPOCOs
suggest changeData classes in kotlin are classes created to do nothing but hold data. Such classes are marked as data
:
data class User(var firstname: String, var lastname: String, var age: Int)
The code above creates a User
class with the following automatically generated:
- Getters and Setters for all properties (getters only for
val
s) equals()
hashcode()
toString()
copy()
componentN()
(whereN
is the corresponding property in order of declaration)
Just as with a function, default values can also be specified:
data class User(var firstname: String = "Joe", var lastname: String = "Bloggs", var age: Int = 20)
More details can be found here Data Classes.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents