https://kotlinlang.org logo
Title
r

rnathani

10/31/2018, 1:12 PM
Hello, I am new to kotlin and I was wondering if there is a way to destroy kotlin object so init block is reinitialized. This is for testing purpose?
n

Nikita Khlebushkin

10/31/2018, 2:24 PM
No, but you can create a new instance of it
c

Czar

10/31/2018, 2:24 PM
That does not make sense in Kotlin or Java world, constructor is only called once, if you "destroy" the object, you'll need to create a new one, which kinda does what you want. so
var yourObject = YourObject(/* params */)
yourObject = YourObject(/* params */)
Note that,
yourObject
variable will point to a newly create object in this case, while initial one will be inaccessible unless there are other references to it and will be garbage collected at some point.