Skip to main content

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

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


Back to the top