These are chat archives for JetBrains/kotlin

May 2017
Luca Guadagnini
May 31 2017 11:17
hi there all! :smile:

is there any difference between:

data class MyDataClass(val field:String)
// and
class MyClass(val field:String)

? I mean under the hood the generated classes are identical, or there are some other things that I need to consider? I'm not talking about semantic and anything, I just want to know what it is happing during compilation time :smile:

Jan Vladimir Mostert
May 31 2017 14:47
@tryIO yes, there is a difference, the data class generates some extra helper methods like copy
Luca Guadagnini
May 31 2017 14:50
but beyond that nothing more, right?
Jan Vladimir Mostert
May 31 2017 14:51
from the docs:
The compiler automatically derives the following members from all properties declared in the primary constructor:

equals()/hashCode() pair,
toString() of the form "User(name=John, age=42)",
componentN() functions corresponding to the properties in their order of declaration,
copy() function (see below).
If any of these functions is explicitly defined in the class body or inherited from the base types, it will not be generated.
Luca Guadagnini
May 31 2017 14:53
Jan Vladimir Mostert
May 31 2017 14:54
By the way, all the action is happening on Slack, 12k Kotlin devs are there
Luca Guadagnini
May 31 2017 14:57
yeah I should sign in on Slack, I was too lazy to do that :blush:
Jonas mg
May 31 2017 19:38
@ice1000 at Dart, null aware operators can help with things; if something can be null then you should be checking for it