I want to use local variable annotations to do better AOP. One idea is to implement the Future<T> concept with a proxy using an annotation.
@NonBlocking ExpensiveObject exp = new ExpensiveObject();
//returns immediately, but has threaded out instantiation of the ExpensiveObject.
exp.doStuff();
//okay, now it blocks until it's finished instantiating and then executes #doStuff
Can I sick AspectJ on this somehow and get what I want done with local variable annotations? I know other threads have indicated that Java doesn’t really support them but it would be magical. I really don’t want to pass around a Future and break encapsulation.
You can not do this with a proxy, but real aspectj bytecode weaving will get you there if you annotate the type instead of the local variable. (I don’t think local variable access is supported as a pointcut). Anyway, here’s some code.
An annotation:
A class marked with this annotation:
A main class:
and an aspect:
Here is the output from HeavyLifter when you run it as an AspectJ/Java Application from eclipse: