dave08
10/14/2021, 11:36 AMsealed interface Foo
object Bar : Foo
object Baz : Foo
fun <T : Foo> getFooObjects(): List<T> = TODO("How do I get this list?")
fun <T : Foo> getFooObjects(): List<T> = Foo::class.sealedSubclasses.filterIsInstance<Table>()
fun <T : Foo> getFooObjects(): List<T> = Foo::class.sealedSubclasses.mapNotNull { it.objectInstance }
Michael de Kaste
10/14/2021, 12:04 PMinline fun <reified T> getObjectsOfType(): List<T> = T::class.sealedSubclasses.mapNotNull { it.objectInstance }
if not, simply
fun getFooObjects(): List<Foo> = Foo::class.sealedSubclasses.mapNotNull { it.objectInstance }
would do the trickdave08
10/14/2021, 12:09 PMsealed interface DbTables
object Foos : IntIdTable("foo"), DbTables
val tables = DbTables::class.sealedSubclasses
.mapNotNull { kclass -> kclass.objectInstance as? Table }
.toTypedArray()
SchemaUtils.drop(*tables, inBatch = true)
SchemaUtils.create(*tables, inBatch = true)