I'm studying creation pattern(Singleton pattern) in android kotlin.
I have question about difference in making singleton object by companion object and object.
In some example, singletons are made like this.
class ABC {
companion object {
private var sInstance: ABC? = null
fun getInstance(): ABC {
if (sInstance == null) sInstance = ABC()
return sInstance ?: throw IllegalStateException("")
}
}
}
but with above method,
// a and b are not same object
val a = ABC()
val b = ABC.getInstance()
println(a == b) // false
but what I know, singleton in kotlin is just object
.
So, my question is "Why, When use companion object to make singleton object"