gmw
gmw

Reputation: 437

Injecting annotated method parameters

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.

Upvotes: 1

Views: 1067

Answers (2)

Jörn Horstmann
Jörn Horstmann

Reputation: 34014

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

Upvotes: 0

Jonathan Feinberg
Jonathan Feinberg

Reputation: 45324

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

Upvotes: 1

Related Questions