DRAFT
Observed
A static method call is dispatched polymorphically at runtime based on the argument types
A static method call is dispatched based on the declared types of the arguments
public class C {
}
public class Sub1 extends C {
}
public class Sub2 extends C {
}
public class Test {
public void test(C c) {
work(c); // this does NOT dynamically dispatch based on c
}
public static void work(C c) { /*implementation*/ }
public static void work(Sub1 s1) { /*implementation*/ }
public static void work(Sub2 s2) { /*implementation*/ }
}
If you want a polymorphic call in Java, you have to use instance methods.
public class C {
public void work() { /*implementation*/ }
}
public class Sub1 extends C {
public void work() { /*implementation*/ }
}
public class Sub2 extends C {
public void work() { /*implementation*/ }
}
public class Test {
public void test(C c) {
c.work(); // this DOES dynamically dispatch based on c
}
}