Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 318
Daniel Gomez Rico Avatar asked Jul 10 '16 01:07

Daniel Gomez Rico


1 Answers

Use default arguments:

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

(also, consider using val).

like image 128
Cedric Beust Avatar answered Sep 17 '22 16:09

Cedric Beust