Java / MapStruct Java Interview questions part 2
Why doesn't MapStruct use reflection at runtime?
MapStruct's design goal is for generated mappers to be indistinguishable from hand-written mapping code in terms of performance and debuggability. Runtime reflection is exactly what would work against that goal - it re-resolves field and method information on every call and forces the JVM through additional access-check and invocation paths that ordinary method calls don't pay.
By resolving all type and property information once, at compile time via the annotation processing API, MapStruct can emit direct getter/setter calls in the generated source. This also means IDEs, debuggers, and stack traces all show plain Java code, so a mapping bug can be stepped through like any other method rather than inspected through a reflective call stack.
More Related questions...