Recursive lambda on field declarations in local classes and anonymous classes.

maurizio cimadamore maurizio.cimadamore at oracle.com
Tue Feb 21 15:32:19 PST 2012


I will look into this - thanks for the report.

Maurizio

On 21-Feb-12 10:44 PM, bitter_fox wrote:
> Hi,
> To use recursive lambda expressions, we have to use that statement:
>      SAM sam = () ->  sam.invoke();
>
> However, the newest compiler rejects it on field declarations in local
> classes and anonymous classes.
> Cannot we use recursive lambda expressions in these situations?
>
> public class Main
> {
>      interface SAM
>      {
>          void invoke();
>      }
>
>      SAM sam = () ->  sam.invoke(); // Legal
>
>      class Inner
>      {
>          SAM sam = () ->  sam.invoke(); // Legal
>      }
>
>      Object obj = new Object()
>      {
>          SAM sam = () ->  sam.invoke(); // Illegal
>      };
>
>      public static void main(String[] args)
>      {
>          class Local
>          {
>              SAM sam = () ->  sam.invoke(); // Illegal
>          }
>
>          new Object()
>          {
>              SAM sam = () ->  sam.invoke(); // Illegal
>          };
>      }
>
>      public void method()
>      {
>          class Local
>          {
>              SAM sam = () ->  sam.invoke(); // Illegal
>          }
>
>          new Object()
>          {
>              SAM sam = () ->  sam.invoke(); // Illegal
>          };
>      }
> }
>
> Regards,
> bitter_fox
>



More information about the lambda-dev mailing list