In my project, I defined an annotation similar to the following:
(Lowering @Retention, @Targetfor short)
public @interface DecaysTo {
String[] value();
}
Ever since he started writing, our needs have changed, and now I have defined an enumeration that I want to use instead of a string:
public enum Particle {
ELECTRON,
ANTIELECTRON,
NEUTRINO,
ANTINEUTRINO,
...
}
In order not to update each instance of this annotation, I would like to be able to create an annotation using Stringor a member enum Particlewithout having to update each instance of this annotation to indicate an attribute. However, since we are defining annotation attributes rather than constructors, it seems impossible to overload it.
public @interface DecaysTo {
String[] value();
Particle[] value();
}
@DecaysTo({"Electron", ...})
@DecaysTo({Particle.ELECTRON, ...})
public @interface DecaysTo {
String[] stringVals();
Particle[] enumVals();
}
@DecaysTo(stringVals = {"Electron", ...})
@DecaysTo(enumVals = {Particle.ELECTRON, ...})
Also tried:
public @interface DecaysTo {
Object[] value();
}
Is there a way to do this that doesn't require returning and editing a huge amount of code?