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

wildcards and generic vararg method invocation causes runtime error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • 9
    • 9
    • 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.

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

              Created:
              Updated:
              Resolved: