r/java • u/artpar • Oct 05 '23
How does the lombok magic work underneath?
https://www.unlogged.io/post/how-does-the-lombok-magic-work-underneath
133
Upvotes
r/java • u/artpar • Oct 05 '23
View all comments
Show parent comment
7
u/Practical_Cattle_933 Oct 05 '23
I’m not pron, but basically self-modifying code is a big no-no for a very good reason. It’s hard enough to reason about static code, let alone if it changes. While new classes can still change the behavior of code, this is done in an expected way (if you have a non-final class, you can expect someone else to subclass it - only that is possible with annotation processors as well) - so even the usage of multiple, complex annotation processors in a project may still be feasible.
You can actually see this issue with lombok, even though it only does trivial modifications: an “old”, but infamous mistake many junior engineers make is using lombok carelessly with JPA entities — calling a toString() in a debug print might just make a db connect/throw an exception, because that toString calls a getter now under the hood.