blob: d9ea38b88a8b787d4d16c38ed65f192c8f571ac4 (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import org.aspectj.testing.Tester;
public class OverridingInterfaceObjectMethod {
private static final int VALUE = 10;
public static void main(String[] args) {
Identifiable i = new C();
Tester.checkEqual(i.hashCode(), 42); //System.identityHashCode(i));
i.setId(new Id(VALUE));
Tester.checkEqual(i.hashCode(), VALUE);
}
}
//TODO explore complicated inheritance hierarchies
class C implements Identifiable {}
interface Base { }
interface Identifiable extends Base {
void setId(Id id);
Id getId();
}
class Id {
public Id(int value) {
this.value = value;
}
int value;
}
aspect IdentifiableAspect {
private Id Identifiable.id = null;
public Id Identifiable.getId() {
return this.id;
}
public void Identifiable.setId(Id id) {
this.id = id;
}
public int Identifiable.hashCode() {
return (this.getId() == null)
? super.hashCode()
: this.getId().value;
}
public int Base.hashCode() {
return 42;
}
}
|