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

wildcards and generic vararg method invocation causes runtime error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: tools
    • Subcomponent:
    • Introduced In Build:
      b23
    • Introduced In Version:
      9
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: