How Lombok generates code onto existing class? [duplicate]

我的未来我决定 提交于 2019-12-04 23:35:13
Douglas

Seems like a duplicate of How does lombok work?, and I would flag to close as dupe but your bounty's preventing it.

In short, Lombok doesn't actually generate code at all. Instead, it uses unspecified and undocumented internal compiler implementation api calls to directly modify the program's abstract syntax tree between reading the source code and outputting compiled bytecode. It could break without warning or notice on updating to a new compiler version, but there's currently no other way.

Lombok is generating code during the compilation phase. Here is a tutorial for that http://hannesdorfmann.com/annotation-processing/annotationprocessing101 .

If you are all new to declaring your own annotations i strongly recommend getting started with runtime annotations. They are easier to understand and debug and your code "acts" during the runtime phase you are already familiar with. A short tutorial for that: http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!