Here is the annotation:
@Target(value = ElementType.TYPE)
@Retention(value = RetentionPolicy.RUNTIME)
@Inherited
public @interface MyAnnotation {
String
Here is the working solution from kriegaex in its entirety:
public aspect AnnotationTests {
public aspect AnnotationTests {
after(Object myObject) returning : execution((@MyAnnotation *).new(..))
&& this(myObject) {
System.out.println("Object class name: " + myObject.getClass().getName());
}
}
}
@MyAnnotation(name="foo")
public class ClassA {
public ClassA() {
// Do something
}
public static void main(String[] args) {
ClassA classA = new ClassA();
ClassB classB = new ClassB("");
if (classA.getClass().getName().equals(classB.getClass().getName())) {
throw new RuntimeException("Big problems!");
}
}
}
@MyAnnotation(name="bar")
public class ClassB {
private final String aString;
public ClassB(String aString) {
this.aString = aString;
}
}