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

Array of generic lambda

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 8
    • specification
    • x86_64
    • linux

      FULL PRODUCT VERSION :
      ava version "1.8.0"
      Java(TM) SE Runtime Environment (build 1.8.0-b129)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b69, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux lyre 3.11.0-17-generic #31-Ubuntu SMP Mon Feb 3 21:52:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Creation of array of generic Function failed at execution (ok at compilation) . I'm not sure that's a bug, but I don't undersatand why it doesn't work with lambda. Note : using a Vector of generic Function works fine

      Thanks


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      just compile and execute the code


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.util.function.Function;


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.function.*;
      class Test {
          public static void main(String [] args) {

      Function<Integer,Integer> f = (x) -> {
      Function<Integer,Integer> [] tf = (Function<Integer,Integer>[]) new Object[1];
      tf[0] = (z) -> z+1;
      return tf[0].apply(x);
      };
      System.out.println(f.apply(4));
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      import java.util.function.*;
      import java.util.*;

      class Test {

          public static void main(String [] args) {
      Function<Integer,Integer> f = (x) -> {
      Vector<Function<Integer,Integer>> tf = new Vector<Function<Integer,Integer>>();
      tf.add((z) -> z+1);
      return tf.get(0).apply(x);
      };
      System.out.println(f.apply(4));
          }
      }


      SUPPORT :
      YES

            abuckley Alex Buckley
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: