Java / Micronaut Interview questions
Why does Micronaut avoid using reflection?
Reflection is flexible but expensive: it involves runtime introspection of classes, is slower than direct method calls, increases memory usage for metadata, and, critically for native images, GraalVM can't statically analyze reflective calls without explicit configuration, making apps harder to compile ahead of time.
Micronaut avoids it by generating equivalent information at compile time. Instead of using Class.getDeclaredFields() or Method.invoke() to inspect and call code at runtime, its annotation processor emits classes like BeanDefinition, BeanIntrospection, and AOP proxies that contain hand-written-equivalent method calls and field accessors, produced automatically.
This has three compounding benefits: faster execution since there's no reflective overhead, lower memory use since there's no need to cache reflective metadata, and near-seamless GraalVM native image compatibility, since the generated code is ordinary bytecode the native-image tool can analyze normally.
More Related questions...