0

I would like to define an annotation for methods that could execute some code before the method starts.

As I understand, it is possible to use proxy and invocation handler to perform this kind of task ( like for instance in : http://www.concretepage.com/java/dynamic-proxy-with-proxy-and-invocationhandler-in-java). However this means first defining an interface, then a class that implements that interface, and then use the proxy.

so if there is some existing code, already using an class, this technique will not allow me to add the annotation and leave everything else unchanged..

is there a way to make such annotations in java ?

thanks

user3617487
  • 155
  • 11
  • Annotations are nothing but markers. You have to create some kind of container that will give you the proxy if such annotation is present on the given method. Container can use Reflections API to find the annotated methods – Gurwinder Singh Dec 08 '16 at 13:13
  • yes of course, I get that. that's why I added the link on the proxy. My concern is more about: is there a way to add the proxy mechanism without having the class that will benefit from the annotation to know about the interface and all of the stuff ? this can be done in python, that's why I'm asking, because I'm new to java, and just don't know if it's not possible, or it's just that I didn't found the way around to make it work. – user3617487 Dec 10 '16 at 18:14

0 Answers0