Hello, I am new to kotlin and I was wondering if t...
# announcements
r
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
No, but you can create a new instance of it
c
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
Copy code
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.