Reflection is Dead, Long Live Annotation Processing!
summary
Reflection is slow and brittle for wiring and mass instantiation, so compile-time annotation processing generates concrete code instead: a custom @Fact annotation plus a JSR 269 processor that writes Java source produces a CourseFactory class at compile time. Measured differences: reflection instantiation = 20ms vs direct 3ms, Spring startup hitting ~0.5s bare and 3.5s with services (sometimes 10–20s). Tooling uses javac with -processor, META-INF/services, manual string-based source generation (JavaPoet optional), and the generated factory works but requires adjusting the build classpath.
AI-written summary · about
chapters (10)
- 0:00Introduction to meta-programming
- 1:28Abstraction and its limits
- 6:04Reflection limitations and performance
- 10:48Runtime vs compile-time meta-programming
- 12:12What is annotation processing
- 15:43Annotation processor basics
- 16:51Factory pattern with annotation processing
- 22:18Compiling and packaging the processor
- 23:53Using the annotation processor
- 26:38Q&A and closing remarks
