'Lombok @Getter and @Setter annotations are not being recognised when getAnnoations() method is used

Lombok @Getter and @Setter annotations are not being recognised when getAnnoations() method is used with a variable by reflection. Any suggestions on how to test if these annoations are present using reflection?



Solution 1:[1]

You cannot check for those annotations during runtime, as they are compile-time-only annotations (RetentionPolicy.SOURCE) which are discarded by the compiler and thus not present in the compiled class files.

There is no way to find out during runtime whether a setter/getter method was generated by lombok or written manually.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jan Rieke