Commons Annotation Proxies - rhjoerg/rhjoerg-java GitHub Wiki
Home > rhjoerg-java-commons > Annotation Proxies
Properties
The created proxy:
- returns the default values of the given annotation class, if not overwritten by the provided map.
- returns correct equality, if compared to a "real" instance.
- returns the same hashCode as a "real" annotation instance.
- is not serializable (yet)
Usage
Given the following annotation:
@Documented
@Retention(RUNTIME)
public static @interface TestAnnotation
{
String foo();
String bar() default "bar";
String[] foobar() default { "foo", "bar" };
}
... add the following snippet to instantiate it:
import static ch.rhjoerg.commons.annotation.Annotations.annotationProxy;
...
TestAnnotation annotation = annotationProxy(TestAnnotation.class, Map.of("foo", "foo"));
The given map must include at least those values without a default value. It may of course overwrite one or more of these values:
annotationProxy(TestAnnotation.class, Map.of("foo", "foo", "bar", "baz"));