bumped into a compiler NPE when replaced lambda with an anonymous class

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Feb 14 06:57:07 PST 2013


This will do:

class CompilerError {

      public static void main(String[] args) {
          SAM s = ()-> { SAM s2 = ()->{ new Object() { }; }; };
      }

      interface SAM {
          void m();
      }
}


 From the stack trace it looks like the the translator is missing that 
the anon class occurs in a static context and therefore no 'enclosing 
this' should be added.

Maurizio

On 14/02/13 14:38, Dmitry Bessonov wrote:
> class CompilerError {
>
>       public static void main(String[] args) {
>           Bar bar = a -> a.aMethod((ClassB) () -> new ClassB() {
>               public void bMethod() {
>               }
>           });
>       }
>
>       public static interface Bar {
>           void barMethod(ClassA a);
>       }
>
>       public interface ClassA {
>           public void aMethod(Object t);
>       }
>
>       public interface ClassB {
>           public void bMethod();
>       }
>
> }



More information about the lambda-dev mailing list