Consider this code:
class Foo {
public void doIt(String... strs) {
System.out.println("this is varargs");
}
private void doIt(String str) {
System.out.println("this is single");
}
}
class Bar {
public static void main (String[] args) {
new Foo().doIt("");
}
}
With javac version 1.6.0_29, it fails to compile, stating:
VarArgsError.java:14: doIt(java.lang.String) has private access in Foo
new Foo().doIt("");
^
1 error
Yes, this is silly code and there are at least two obvious workarounds, but I’m curious. Based on section 15.12.2 of the specification, this compilation error seems like a bug in javac, because the first step should remove the non-varargs doIt, as it is inaccessible according to section 6.6.1. Am I missing some other details in the lookup algorithm or is this as obviously wrong as I think it is?
You’re not missing anything.
This is a known bug.
As Qwe commented, here is a link to an appropriate bug filing:
https://bugs.java.com/bugdatabase/view_bug?bug_id=6746184