views:

98

answers:

2

In Java 6, is it possible to inject some value into a (@Target(ElementType.PARAMETER) and @Retention(RetentionPolicy.RUNTIME)-meta-annotated) method parameter? It's entirely possible to find the annotation at runtime using reflection, it's just that there seems to be no way of actually modifying the parameter's value.

Or is that strictly Java 7 (or some yet-to-be-finalized JSR)? I can't see how it would be possible (other than perhaps using bytecode manipulation) in Java 6.

+1  A: 

Rather than doing the bytecode manipulation yourself, it's less work to use something like AspectJ with an annotation pointcut.

Jonathan Feinberg
That's interesting, thanks for your answer!
magnus.wissler
A: 

If your Method is declared in an interface you could also look into java.lang.reflect.Proxy and InvocationHandler.

Jörn Horstmann
Thanks for your answer, but unfortunately it's a POJO.
magnus.wissler
Nope, no interface here (except the @interface declaration of the annotation of course). All that appears to be accessible from the Reflection API (excluding dynamic proxies) is the type of the parameter, not its actual value.
magnus.wissler