I recently read an article talking about the Java annotations, and on this latter comes the @Generated one. They say that it is used for automatically generate code.
Could someone explain me that in further with a little example ?
All what i found on the net was some pro question or something beyond what i was looking for.
@generated annotation is kind of bookmark to indicate the respective code is autogenerated by tools. So that if any IDE who respects it may block the code to edit.
As the documentation states, it is for you to know that this is a lombok generated method/field/etc. This helps the IDE to identify the generated classes and warn you from modifying them.
Annotations have a number of uses, among them: Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings. Compile-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
As we briefly mentioned, annotations processors are typically used to inspect the codebase against the presence of particular annotations and, depending on use case, to: generate a set of source or resource files. mutate (modify) the existing source code. analyze the exiting source code and generate diagnostic messages.
As per the JavaDoc:
The Generated annoation is used to mark source code that has been generated. It can also be used to differentiate user written code from generated code in a single file.
@Generated
is used by meta-programs such as Auto/Value which generate source code so you don't have to manually write it. If you're writing a .java
file by hand (which is normally what one does), don't use @Generated
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With