3 ms·
You can’t change code either in Java — annotation processors are explicitly unable to do that — Spring’s magic works through loading new classes up that either
by kaba0 4y ago
You can’t change code either in Java — annotation processors are explicitly unable to do that — Spring’s magic works through loading new classes up that either implement the same static interface you use, or extending the class, and injecting this new proxy instead.
In short, if you want to log certain methods at enter and exit time with AOP (not manually adding it everywhere), you just create a proxy object and do a logEnter(); targetedObj.method(); logExit();
That’s why some people dislike Lombok as that actually changes byte code at compile time.
- samus 4y agoThe bytecode format is well-documented. If Lombok would just augment these, then there would be no major problem with it. But it actually does something worse: it uses reflection and other tricks to extend the Abstract Syntax Tree, which is purely an implementation detail of the Java compiler. And it must do the same with every tool that touches Java Sources.