orangy
for (property in MyClass::class.properties) { … }
The compiler knows statically which properties are there and can unroll the loop. Then, if you add
for (property in MyClass::class.properties) {
when (property.type) {
Int::class -> callInt(property.name, property.get())
… other types …
}
}
While unrolling the loop compiler can eliminate all the cases and insert just specific calls for each property, inserting constant strings for property names, insert direct property access for get
, etc. There are lots of caveats even in this naive idea. But still, that could be cool some day in the future 🙂