I think the overall sentiment is that reflection is slow and shouldn’t be used often, but also not slow enough not to be used ever 😉
*I don’t have sources for that statement though
02/25/2020, 3:25 PM
Avoid it. The kotlin-reflect library is large in terms of apk size and reflection is indeed slow. This is compounded on Android since the system expects to be able to kill -9 your app at any time and restart it any time it's needed, so one-time reflection that is cached still hurts your ability to become interactive quickly or launch work in the background like handling broadcasts or jobs.
If you can do it statically, it's generally worth that approach instead, even if that means code generation
02/25/2020, 4:28 PM
Reflection can also break easier IMO
I guess ideally tests would catch that for you, but that's not always airtight in my experience
02/25/2020, 5:52 PM
Thanks guys. Current use case is diffing various data classes against each other to see which fields are different - idea is to present a timeline of records, and highlight, in each record those fields which have changed from the previous record. Wrote a solution in js in 2 mins which I hoped would run on a server, but now I am being asked to provide a solution client-side.
Holger Steinhauer [Mod]
02/26/2020, 10:26 AM
If you change your state in only one place you can keep track of the changes. And yes, it sounds like Redux for a reason 😉