public class C {
public final class Inner {
public void use(Inner i) {}
}
public void use(Inner i) {};
private static void javaClient() {
C c1 = new C();
C c2 = new C();
Inner i1 = c1.new Inner();
Inner i2 = c2.new Inner();
// javac doesn't track the outer instance in the types
c1.use(i1);
c1.use(i2);
i1.use(i1);
i1.use(i2);
}
}
Analogous client code from Scala fails to compile jointly.
class Client {
def client() {
val c1 = new C
val c2 = new C
val i1 = new c1.Inner
val i2 = new c2.Inner
c1.use(i1)
c1.use(i2)
i1.use(i1);
i1.use(i2);
}
}
The following is legal Java code
Analogous client code from Scala fails to compile jointly.