Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] O'Reilly article on Lazy Loading with AspectJ

Russell Miles wrote:
Any feedback is always great :)

I found the article very interesting.

Wouldn't it be even better if (in the MainApplication) you could just write

features[0] = new FeatureA();

And then put some advice around those constructor call's where you actualy execute the "initializeFeature" method from the aspect. That would make it more oblivous to the programmer of the main application. I would also make the "lazy loading" concern completely "plug-and-play".

I've been toying a bit with your code and this idea, but I can't get it right. I'm always running into ClassCastExceptions when advizing a constructor to return something else then "proceed()".

My code:

protected pointcut init() :  call(public features.Feature+.new(..))
   && !within (LazyLoading) && !within (LazyFeatureProxy);
		
Object around () : init () {
   //"FeatureA" should be obtained with reflection,
   //but this will do for now
   Feature f = initializeFeature ("FeatureA");
   return f;
}

But this gives a ClassCastException on the statement

features[0] = new FeatureA();

in the MainApplication.

Is there a way to advice a constructor to return something else (implementing the same interface), or is it just not possible?

thanks in advance,
Jan Van Besien


Back to the top