JDK-8049230 : Wildcard-parameterized type vararg method invocation fails to compile
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2014-07-03
  • Updated: 2014-07-03
  • Resolved: 2014-07-03
Related Reports
Duplicate :  
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:

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

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