in this code, is there a way to avoid creating IdH...
# codereview
c
in this code, is there a way to avoid creating IdHandler twice?
Copy code
internal data class EntityInfo<T:Any>(val idHandler: IDHandler, val classInfo: ClassInfo<T>) {
    constructor(kClass: KClass<T>) : this(Table(kClass), IDHandler(kClass), ClassInfo(kClass, IDHandler(kClass)))
}
i guess its not possible because the primary constructor call has to be the first instruction of the secondary constructor so I cannot extract a variable for IdHandler(kClass)
s
you’re probably better off with a factory function in the companion object tbh
c
or a top level method named like a constructor
Copy code
fun <T:Any>EntityInfo(kClass: KClass<T>): EntityInfo<T> {
    val idHandler = IDHandler(kClass)
    return EntityInfo(Table(kClass), idHandler, ClassInfo(kClass, idHandler))
}
internal data class EntityInfo<T:Any>(val table:Table, val idHandler: IDHandler<T>, val classInfo: ClassInfo<T>)