Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Final Classes

Paulo,
 
Just remove the final from your advice and you should be good to go.  At least I was.  Here is what it should look like:
 
  pointcut finalClasses() : execution(*.new(..)) && !within(DetectFinalClassesAspect);
 
The reason this fails is that final as a modifier is not allowed on a constructor, therefore aspectj can not pick it up.
 
Ron

 
On 12/23/05, Paulo Alexandre Corigo Zenida <paulo.zenida@xxxxxxxx> wrote:
Good morning,

       I was trying to capture calls to the constructores of a final class with the
following example but I couldn't do so. Am I doing something wrong or isn't
possible to capture final classes? In the case of not being possible to
capture final classes, could someone tell me why, please?

Here's my final class:

final public class FinalClass {

       public void foo() {
               System.out.println("FinalClass.foo()");
       }
}

The testing class, which simply creates an instance of my FinalClass class and
executes its foo method:

public class Test {

       public static void main(String args[]) {
               FinalClass fc = new FinalClass();
               fc.foo();
       }
}

And here's the Aspect I have created in order to capture calls for the
constructors of final classes:

public aspect DetectFinalClassesAspect {

       pointcut finalClasses() : execution(final *.new(..))
&& !within(DetectFinalClassesAspect);

       // This is not being applied to anything!!!
       before() : finalClasses() {
               System.out.println("Before final class: " + thisJoinPointStaticPart);
       }
}

Thanks in advance. Best regards,

       Paulo Zenida
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top