0

So, we got a enum type with some annotations:

@AnnotationName(parameter1="value1", parameter2="value2")
public enum enumType {

    VALUE1,
    VALUE2

}

We got a class that is using this enum type, and we need to change the value of the annotation for a unit test. I've been suggested to use reflection, but I'm not finding a clear way to make this. There's any simple way to access this field (which is a custom annotation, by the way) and update the values.

Neuromante
  • 531
  • 2
  • 12
  • 29
  • https://stackoverflow.com/questions/14268981/modify-a-class-definitions-annotation-string-parameter-at-runtime - But note that this is very fragile – ekalin Feb 04 '20 at 17:17
  • Or more specifically this [link](https://rationaleemotions.wordpress.com/2016/05/27/changing-annotation-values-at-runtime/) from the comment section of the accepted answer: – second Feb 04 '20 at 17:33
  • 2
    There is no clear way. And it’s the wrong approach anyway. Separate the code into the code fetching the annotation from the class and the code using the annotation value. Then, you can easily test the latter by passing custom values to it. – Holger Feb 04 '20 at 18:19

0 Answers0