Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6558596

Private members hides var args methods

XMLWordPrintable

    • generic
    • generic

      Rob [...] has discovered something that Neal and I believe to be a javac bug. Consider this program:

      public class Foo {
        public static void main(String[] args) {
          Bar bar = new Bar();
          bar.add("Hello");
          bar.add("Hello, world", "Buddy");
        }
      }

      class Bar {
        public void add(String... ss) {
          System.out.println("Array");
        }

        private void add(String s) {
          System.out.println("Element");
        }
      }

      In javac (1.5 and 1.6) it won't compile, but generates this error message:

      Foo.java:4: add(java.lang.String) has private access in Bar
          bar.add("Hello");
             ^
      1 error

      In Eclipse, it compiles.

      Looking in JLS 3, we see that the compiler should first look for applicable methods w/o boxing unboxing, or varargs. It should find non, and go on to phases two and three. It should find the varargs method in phase three, but it never gets there. If you agree with this analysis, please file a bug report. If not, please tell us where we goofed.

                     Thanks,

                     Josh (and Neal)

            Unassigned Unassigned
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: