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
4
u/rzwitserloot Oct 06 '23
Ron says it's not java. That's different from "it does not conform to spec X".
If Ron said: Lombok as an annotation processor does not conform to the AP spec, I would agree with that statement. But that's not what Ron is saying. What he does say is misleading at best. Wrong is more likely.
The JLS just covers the language itself, it does not cover the standard library. Nowhere in the JLS will you find, for example, any notes whatsoever about
java.util.FileOutputStream. Does writingnew FileOutputStream()somehow make your code non-java? Surely not. Lombok does not modify the meaning of any java constructs at all, and the code you write even with lombok in your project must be syntactically valid java. If you remove lombok from the compilation process and then try to compile code written with lombok in mind, sure, it won't compile. But then, the exact same thing happens if you try to use, say, Immutables. That's an inherent part of the annotation processor spec: During a compile run, some code can refer to constructs that do not (yet) exist; that's why the AP system runs in rounds, so that round 1 can add the stuff that other code is referring to that doesn't exist yet.Annotation Processing isn't in the JLS either I think, I think that's a different spec. Regardless, I see only two options:
class ThisIsEvidentlyNotJava { public boolean equals(Object other) { return true; }}- is not java either. Because it breaks a spec. Not the JLS, but the contract as stipulated in theequalsmethod's javadoc. I think that's a bizarre definition of what 'not java' is understood to mean. (it breaks a few things from the equals spec, one of them: Thata.equals(b)must necessarily meana.hashCode() == b.hashCode()which would not be true for instances ofThisIsEventlyNotJava).