I'm trying to save an object inside Firebase database from Kotlin,
I dont feel right providing a default empty constructor and put values as nullable
, having to change all my code bc of this.
My class:
class Video(var id: String, var url: String, var owner: User) : {
constructor() : this("", "", User("", "", ""))
}
Firebase push:
FirebaseDatabase.getInstance().reference.child("public").push().setValue(video)
Error:
is missing a constructor with no arguments
Is there a better solution for this?
Use default arguments:
class Video(var id: String = "", var url: String = "",
var owner: User = User("", "", ""))
(also, consider using val
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With