Caipivara Caipivara - 3 years ago 265
Android Question

Empty constructor for kotlin object to use Firebase

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?

Answer Source

Use default arguments:

class Video(var id: String = "", var url: String = "",
    var owner: User = User("", "", ""))

(also, consider using val).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download