Reputation: 7507
So I have a problem that I'm not sure is solvable well.
I have a library that has a method annotation
@Retention(RetentionPolicy.RUNTIME)
public @interface CallbackHandler {...}
For the next version of the library, I would like to copy this annotation and rename it, but leave this old annotation around with @Deprecated for backward compatibility, so there isnt a hard break while people make the switch.
The problem is since I can't subclass the annotation, I have to write all of the code twice to handle the two different annotations. I would like to avoid this at it's problematic and a big time sink.
So the question is there any way to rename the annotation for the new version but keep backward compatibililty while not having to write two versions of the code?
Upvotes: 0
Views: 371
Reputation: 18990
One way coming to my mind is using an annotation proxy such as this one or or this one from the Hibernate Validator project (disclaimer: I'm a committer of the latter).
You could create a proxy for your old, now deprecated annotation based on the attribute values from the new annotation. That way your code for processing the annotation can stay unchanged.
Or you refactor your code to process the new annotation type and create a proxy for the new annotation type when discovering the old one, which you can phase out that way later on.
Upvotes: 1