Created
March 16, 2017 11:43
-
-
Save struberg/1fe5d848736259687a852dbb84f71fa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Consider the following annotation | |
@Qualifier | |
public @interface ConfigProperty { | |
@Nonbinding | |
String value() default ""; | |
} | |
If I like to programmatically create an annotation instance then I can write | |
private static class ConfigPropertyLiteral extends AnnotationLiteral<ConfigProperty> implements ConfigProperty { | |
@Override | |
public String value() { | |
return ""; | |
} | |
} | |
Now what happens if later (in a spec change) some attributes gets added? | |
E.g. | |
@Qualifier | |
public @interface ConfigProperty { | |
@Nonbinding | |
String value() default ""; | |
boolean mandatory() default true; | |
} | |
After this change my ConfigPropertyLiteral blows up as it doesn't implement the mandatory() method! | |
Is there a way to declare default methods on annotations? Not as far as I know... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment