strange choice of method
Stephan Herrmann
stephan.herrmann at berlin.de
Sun Jun 8 22:22:19 UTC 2025
In the following code javac raises exactly one error:
//--------------
public class X {
void a() {}
private static void a(String s) {}
private void c() {}
private static void c(String s) {}
static class M1 extends X {
public void x() {
a(null);
c(null);
}
}
static class M2 {
public void x() {
a(null);
c(null);
}
}
}
//----------------
The first call "a(null)" is rejected, because the no-arg instance method is
selected, whereas the second such call is accepted, targeting the static method.
Also both calls "c(null)" are accepted.
Is there any intention behind this?
thanks,
Stephan
PS: These observations hold for version 5 through 25 ea. javac 1.4 actually
accepts the program. Not sure if it helps understanding the why of it.
More information about the compiler-dev
mailing list