jeudi 11 mai 2023

Named fields for another class

I need to access some private fields via reflection. While this is considered bad, it is an external library and I have no other way to access it. The field names (and types) are known in advance (during compile time) and as a precaution for future library updates I want the compiler to throw an error when this field doesn't exist anymore.

Lombok has the annotation @FieldNameConstants which generates all field names as static Strings. When the field doesn't exist anymore, the static variable won't generate and the compiler will throw an error. This would be a great solution, but as this is an external library class I cannot annotate it with lombok.





Aucun commentaire:

Enregistrer un commentaire