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

Strange warning on overridden var args method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 6
    • tools
    • generic
    • generic

      The following program produces warnings only on -Xlint:all.
      However, the warning does not have a prefix to identify its
      lint category.

      import static java.lang.System.out;
      class Base {
          void method1(Object[] args) {
              out.println("Base:method1");
              for (Object arg : args)
                  out.println(arg);
          }

          void method2(Object... args) {
              out.println("Base:method2");
              for (Object arg : args)
                  out.println(arg);
          }
      }


      class Derived extends Base {
          void method1(Object... args) {
              out.println("derived:method1");
              for (Object arg : args)
                  out.println(arg);
          }

          void method2(Object[] args) {
              out.println("derived:method2");
              for (Object arg : args)
                  out.println(arg);
          }
      }
      class Tester {
          public static void main(String[] args) {

              out.println("Working with Base");
              Base b = new Base();
              b.method1(new Object[] { "Hello", "World"});
              b.method2("Hello", "World");
              b.method2(new Object[] { "Hello", "World"});

              out.println("Working with Derivedd");
              Derived d = new Derived();
              d.method1("Hello", "World");
              d.method1(new Object[] { "Hello", "World"});
              d.method2("Hello", "World");
              d.method2(new Object[] { "Hello", "World"});

              out.println("Working with Derived as Base");
              b = d;
              b.method1(new Object[] { "Hello", "World"});
              b.method2("Hello", "World");
              b.method2(new Object[] { "Hello", "World"});


          }
      }

            jjg Jonathan Gibbons
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: