wildcards and generic vararg method invocation causes runtime error

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P2
    • 9
    • Affects Version/s: 9
    • Component/s: tools
    • b23
    • 9
    • generic
    • generic

      Let's consider following code:

      public class Test49 {
          interface Iface<T extends Number> {
              void m(T...t);
          }

          public static void main(String argv[]) {
              Iface<? super Integer> i = (Integer...a) -> System.out.println("lmbd");

              i.m(1, 2, 3);
          }
      }

      this code causes following error at runtime:
      Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Number; cannot be cast to [Ljava.lang.Integer;
              at Test49$$Lambda$1/1421795058.m(Unknown Source)
              at Test49.main(Test49.java:9)

      JDK-8049075 previously caused compiler error in similar case.

            Assignee:
            Vicente Arturo Romero Zaldivar
            Reporter:
            Georgiy Rakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: