If a supertype has componentN() functions that are open and return compatible types, the corresponding functions are generated for the data class and override those of the supertype. If there are explicit implementations of equals(), hashCode(), or toString() in the data class body or final implementations in a superclass, then these functions are not generated, and the existing implementations are used. The primary constructor needs to have at least one parameter.Īll primary constructor parameters need to be marked as val or var.ĭata classes cannot be abstract, open, sealed, or inner.Īdditionally, the generation of data class members follows these rules with regard to the members' inheritance: To ensure consistency and meaningful behavior of the generated code, data classes have to fulfill the following requirements: ToString() of the form "User(name=John, age=42)"ĬomponentN() functions corresponding to the properties in their order of declaration. The compiler automatically derives the following members from all properties declared in the primary constructor: Data class User(val name: String, val age: Int)
0 Comments
Leave a Reply. |