blob: d5dcbda15da4311b1b577b8191923633091b6149 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// TESTING: factory method is non static and takes the object for which the delegate is being created
import org.aspectj.lang.annotation.*;
public class CaseD {
public static void main(String[]argv) {
CaseD cd = new CaseD();
((I)cd).methodOne(); // will only succeed if mixin applied
}
public String toString() {
return "CaseD instance";
}
}
aspect X {
@DeclareMixin("CaseD")
public I createImplementation(Object o) {
System.out.println("Delegate factory invoked for "+o.toString());
return new Implementation();
}
}
interface I {
void methodOne();
}
class Implementation implements I {
public void methodOne() {
System.out.println("methodOne running");
}
}
|