I'm trying to figure out if something is possible....
# announcements
r
I'm trying to figure out if something is possible. Generally, what I'm trying to do is get a class type of a subclass from within the companion object of the superclass ... In the snipped below, treat the
__
as what I need
Copy code
companion object
{
    fun fromSnapshot(snapshot: DataSnapshot): __
    {
        val model = snapshot.getValue(__)
        model.key = snapshot.key
        // ...
        return model
    }
}
Some background ...
DataSnapshot
is from Firebase, and
snapshot.getValue()
takes a
Class<T>
. If I were trying to create an instance of, say, a
TestModel
, code would be as follows
Copy code
companion object
{
    fun fromSnapshot(snapshot: DataSnapshot): TestModel
    {
        val model = snapshot.getValue(TestModel::java.class)
        model.key = snapshot.key
        // ...
        return model
    }
}
I'm not really sure if what I'm asking is possible in Kotlin. I'm pretty sure it isn't in Java. I hate to mention it, but in Swift, this would be accomplished with what I call "big-S self," or
Self
, which is the class type of instance
self
. If you don't know Swift,
self
is equivalent to Java and Kotlin's
this
. Any help would be hugely appreciated!