The @FieldNameConstants annotation generates an inner type which contains 1 constant for each field in your class. The two following are equivalent
import lombok.experimental.FieldNameConstants;
import lombok.AccessLevel;
@FieldNameConstants
public class FieldNameConstantsExample {
private final String iAmAField;
private final int andSoAmI;
@FieldNameConstants.Exclude private final int asAmI;
}
public class FieldNameConstantsExample2 {
private final String iAmAField;
private final int andSoAmI;
private final int asAmI;
public static final class Fields {
public static final String iAmAField = "iAmAField";
public static final String andSoAmI = "andSoAmI";
}
}
How does Lombok achieve that ? I wanted to make my own annotation on each fields where the inner class Fields’ constants are customized (basically @FieldNameConstants(value = “XXX” on each field), but while I understand how to make custom annotations for each field in Java, it seems a far cry from what Lombok does.