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

Wildcard-parameterized type vararg method invocation fails to compile

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • None
    • 8
    • tools
    • None
    • b132
    • 8
    • generic
    • generic

    Description

      Following java class fails to compile:

          public class Test15 {
              interface Iface<T> {
                  String m(T... t);
              }


              public static void run() {
                  Iface<? super Integer> i = null;

                  i.m(Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1));
              }
          }

      The error message is:

          Error:(10, 10) java: method m in interface Test15.Iface<T> cannot be applied to given types;
            required: capture#1 of ? super java.lang.Integer[]
            found: java.lang.Integer,java.lang.Integer,java.lang.Integer
            reason: formal varargs element type capture#1 of ? super java.lang.Integer is not accessible from class Test15

      Removing wild cards from Iface<? super Integer> (turning it into Iface<Integer>) makes compilation to succeed.

      Also please note following differences we discovered:

      JDK7:
            i.m(new Integer[1]); //error
           i.m(Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1)); //ok

      JDK8:
            i.m(new Integer[1]); //ok
           i.m(Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1)); //error

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              grakov Georgiy Rakov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: