Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspectJ 'around' advice - do you have to call 'proceed'?

Tags:

java

aspectj

Here's an easy one, surely someone knows this off the top of their head...

Question

When you write 'around' advice in AspectJ, do you have to call proceed? Lets say you wanted to make a method do something COMPLETELY different? Can you leave 'proceed' out or will it generate an error (forcing you to call proceed but ignore the results)?

Example

can you do something like this:

String around() : generateCommand() {
    //never call proceed
    return getCommanMyOwnWayWithoutAccessingDatabase();
}

or do you HAVE TO do it like this:

String around() : generateCommand() {
    String commandInvolvingInvalidDatabaseCall = proceed();
    //completely ignore results from proceed
    return getCommanMyOwnWayWithoutAccessingDatabase();
}
like image 209
gMale Avatar asked Jun 03 '11 16:06

gMale


1 Answers

Call proceed() or proceed(..) only if you want to call the functionality of your adviced method. So in your case if you want to do something completely different, don't call it.

like image 180
Matej Tymes Avatar answered Oct 05 '22 23:10

Matej Tymes