I'm trying to use Java annotations to be able to add specific fields to an object.
The need is the following : I have a class that processes configuration files where keys are associated with values with the form key=value.
The problem is that I want to be able to let the user defining himself required fields which, if not present, throws exception.
The easiest solution is to pass these fields to the constructor in a String[] but, I also want the user to be able to use these required fields as it were properties of the class, so he's able to write in the code something like :
@RequiredFields(
field1,
field2,
field3)
MyClass myObject = new MyClass(String filePath);
String value = myObject.field1;
and the field field1 is also a completion proposal ?
I'm actually developping in Groovy, so if not possible in standard Java, would it be in Groovy ?
Thanks !