Skip to content

Instantly share code, notes, and snippets.

@struberg
Created March 16, 2017 11:43
Show Gist options
  • Save struberg/1fe5d848736259687a852dbb84f71fa4 to your computer and use it in GitHub Desktop.
Save struberg/1fe5d848736259687a852dbb84f71fa4 to your computer and use it in GitHub Desktop.
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