`val date` and `val source`?
# android
e
val date
and
val source
?
o
i used var
abstract class Message { abstract var date: Long; abstract var source: MessageSource abstract var type: MessageType } data class TextMessage( override var date: Long = 0L, override var source: MessageSource = MessageSource.BOT, override var type: MessageType = MessageType.TEXT, var text: String ) : Message()
g
TextMessage(text = "my text")
and should work already with your code
or just make first constructor argument and you can write
TextMessage("my text")
instead
o
have you tried ? it doesn't work. it asked me to add all the parameteres to the args
can you paste the way you have written your constructor
g
Just copied your code and the first way works
o
thanks buddy it worked
TextMessage(text = "my text")
g
second should work if text will be the first argument:
Copy code
data class TextMessage(
        var text: String,
        override var date: Long = 0L,
        override var source: MessageSource = MessageSource.BOT,
        override var type: MessageType = MessageType.TEXT
) : Message()
Kotlin doesn’t allow to mix optional and non-optional arguments without explicit argument name, so better to put args with default values after other args