I am trying to do some Java annotation magic. I must say I am still catching up on annotation tricks and that certain things are still not quite clear to me.
So... I hav
Well, it's apparently nothing all that complicated. Really!
As pointed out by a colleague, you can simply create an anonymous instance of the annotation (like any interface) like this:
MyAnnotation:
public @interface MyAnnotation
{
String foo();
}
Invoking code:
class MyApp
{
MyAnnotation getInstanceOfAnnotation(final String foo)
{
MyAnnotation annotation = new MyAnnotation()
{
@Override
public String foo()
{
return foo;
}
@Override
public Class extends Annotation> annotationType()
{
return MyAnnotation.class;
}
};
return annotation;
}
}
Credits to Martin Grigorov.