https://kotlinlang.org logo
Title
r

rustyrazorblade

11/21/2019, 9:33 PM
Hey folks. Trying to figure out why accessing the
keyvalue
val inside this object is a problem:
class Tables(val session: Session) {   
   val queries = object {
        val keyvalue = object {
            val insert = prepare("INSERT INTO keyvalue (id, value) values (?, ?)")
            val select = prepare("SELECT * from keyvalue WHERE id = ?")
        }
        val timeseries = object {
            val insert = prepare("INSERT INTO timeseries (id, c, data) values (?, ?, ?)")
            val selectPartition = prepare("SELECT * from timeseries WHERE id = ?")
            val selectPartitionReverse = prepare("SELECT * from timeseries WHERE id = ? order by c DESC")
        }
    }
}
I’m not able to do essentially this:
tables = Tables(session)
tables.queries.keyvalue
anyone know why?
s

Shawn

11/21/2019, 9:35 PM
not sure if you come from a Swift background or something similar where you’d be able to access the properties of anonymous objects like this, but this isn’t legal code in this context. The compiler cannot determine the shape of the object without it adhering to an interface or otherwise having it be typed
r

rustyrazorblade

11/21/2019, 9:46 PM
ok. thanks for the quick answer!
Hmm… looks like you can’t create anonymous objects that implement multiple interfaces either
m

Matteo Mirk

11/22/2019, 8:31 AM
are you sure? IIt seems to me it’s possible for an object to implement interfaces, it works: https://pl.kotl.in/oNXzewedk
Nested access works as well: https://pl.kotl.in/LmGnJ4sQ2
r

rustyrazorblade

12/10/2019, 9:41 PM
I’m not even sure what I was doing at this point, sorry for the absurdly long non-response
m

Matteo Mirk

12/11/2019, 1:35 PM
no worries, it’s always a chance to learn something 😉