Original version; naive translation of the
model into Java.
public void ctv(M m) {// contravariance
System.out.println("ctv(M)
in D");
}
/*
* added code to supress the ambiguity of slot (6,2)
* "correct" the blue difference of the Java
Table.
*/
public void ctv(B b) {//redefinition to force
the choice slot(6,3)
ctv((M) b);
}
public void inv(M m) {// invariance
System.out.println("inv(M)
in D ");
}
}
public static void main(String [] ar) {
U u = new U();
D d = new D();
U w = new D();
T t = new T();
M m = new M();
B b = new B();
System.out.println("-- first
test suite");
u.cv(t);
u.cv(m);
u.cv(b);
//u.ctv(t);
System.out.println("ctv(B)
in U cannot be applied to (T)");
//u.ctv(m);
System.out.println("ctv(B)
in U cannot be applied to (M)");
u.ctv(b);
//u.inv(t);
u.inv(m);
u.inv(b);
System.out.println("-- second
test suite");
d.cv(t);
d.cv(m);
d.cv(b);
//d.ctv(t);
System.out.println("cannot
resolve symbol");
d.ctv(m);
d.ctv(b);
//System.out.println("reference
to ctv is ambiguous, both method ctv(B) in U and method ctv(M) in D match");
//d.inv(t);
d.inv(m);
d.inv(b);
System.out.println("-- third
test suite");
w.cv(t);
w.cv(m);
w.cv(b);
//w.ctv(t);
System.out.println("ctv(B)
in U cannot be applied to (T)");
//w.ctv(m);
System.out.println("ctv(B)
in U cannot be applied to (M)");
w.ctv(b);
//w.inv(t);
w.inv(m);
w.inv(b);
}
}