The pattern Singleton in Kotlin is designed by obj...
# announcements
r
The pattern Singleton in Kotlin is designed by object, so if in java to get an instance of the singleton while we create it : public static SingletonClass getInstance(param1, param2, ...) which will initialize some var "Dynamicly" in the SinletonClass and in the same time create the instance using this params, and as we know there is no constructor in kotlin objects, so how do i pass my params to the object dynamicly ?
g
You cannot
But you can implement this the same way as in Java
It was discussed already a couple times
m
You can't. If you really want an
object
then you could make it wrap a regular
class
and add something like
fun initialize(…)
to your
object
which sets up the wrapped
class
instance. Anytime you access the
object
you throw an exception if
initialize
wasn't called yet.
g
also a side note, I believe this is a very bad anti-pattern
☝️ 7