https://kotlinlang.org logo
Title
e

edwardwongtl

11/16/2017, 6:00 AM
val date
and
val source
?
o

oianmol

11/16/2017, 6:01 AM
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

gildor

11/16/2017, 6:03 AM
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

oianmol

11/16/2017, 6:05 AM
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

gildor

11/16/2017, 6:07 AM
Just copied your code and the first way works
o

oianmol

11/16/2017, 6:07 AM
thanks buddy it worked
TextMessage(text = "my text")
g

gildor

11/16/2017, 6:08 AM
second should work if text will be the first argument:
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