How add method to java class using custom annotation

Viewed 1133

I want to create a java annotation which generates a method in compile-time, like Lombok for example: I have this class :

@MyNewAnnotation()
public class ClassTest {

   private String name;
   private Integer id;
   private String lastName;
   
   public final static String COL_NAME = "NAME";
   public final static String COL_LAST_NAME = "LAST_NAME";

}

I want that's myNewAnnotation can generate the getCol-method which returns "NAME, LAST_NAME" for example:

public static String getCol() {
    return COL_NAME + "," + COL_LAST_NAME;
}

The annotation has to read all attributes which start with "COL_" and with them generate the new method in compile-time, more or less like Lombok when generating getters or setters

0 Answers
Related