is it possible to have non-argument and argument c...
# android
s
is it possible to have non-argument and argument constructors using the constructor syntax example:
class DownloadHelper(internal val tag: String = "") : Fragment()
k
class DownloadHelper @JvmOverloads constructor(internal val tag: String = ""): Fragment()
But you shouldn’t be doing this with android Fragments. The framework will always call the no-arg constructor instead, so you might end up with more side effects that necessary
s
i can just create multiple constructors no problem (or newInstance method) just wondering if there was a cool kotlin way of doing it
k
The issue is not with Kotlin. It is with having multiple constructors for a Fragment. The framework always calls the one with no-arg, so even if you start the fragment using a constructor with arguments, the framework could later recreate teh fragment, and it will use the no-arg one instead
A
newInstance
(or whatever name) factory method is much better
s
yes my question was purely syntactical 🙂
k
Ah. Okay then 🙂
s
cheers for the help anyway
k
You’re welcome