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

Target type of lambda from switch expression can't be inferred from cast outside

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Code such as

              public static void main(String args[]) {
                      Object o = new Object();
                      Object os = (Supplier<Object>) switch(o) {
                              case Object r -> (Supplier<Object>)() -> r;
                      };
              }

      runs without issue, whereas

              public static void main(String args[]) {
                      Object o = new Object();
                      Object os = (Supplier<Object>) switch(o) {
                              case Object r -> () -> r;
                      };
              }

      gives

      error: lambda expression not expected here
                              case Object r -> () -> r;
                                                        ^


            adev Anupam Dev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: