hmm i spoke too fast i think, annotation value should be know before runtime
so it is no so easy, constants need to be real constants no only a static
final var.
Here what i thought and doesn't work:
@Foo.MyAnnotation(value = Foo.VALUE)
public class Foo {
public static final String VALUE = "-";
static {
try {
Field field = Foo.class.getDeclaredField("VALUE");
field.setAccessible(true);
Field modifiersField =
Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() &
~Modifier.FINAL);
field.set(null, System.getProperty("value", "default"));
System.out.println("done: " + field.get(null));
} catch (Exception e) {
System.err.println("can't do it :(");
e.printStackTrace();
}
}
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
String value() default "";
}
}
well it will be easier to patch openejb i guess
- Romain
2011/9/7 Jacek Laskowski <[email protected]>
> On Wed, Sep 7, 2011 at 10:29 PM, Romain Manni-Bucau
> <[email protected]> wrote:
>
> > if you speak about built-in feature i don't think but i think we can use
> > constant in annotation so just initialize some constants from system
> > properties no?
>
> It sounds very promising. Would you elaborate? An example would be helpful.
>
> Jacek
>
> --
> Jacek Laskowski
> Java EE, functional languages and IBM WebSphere - http://blog.japila.pl
> Warszawa JUG conference = Confitura (formerly Javarsovia) ::
> http://confitura.pl
>