Hi,
I have the following structure and want to use lambda expressions with it, but an exception occurs:
class SuperClass // (package private)
public class SubClass extends SuperClass // in same package as SuperClass
I have a functional interface (a listener), which has one argument of type SubClass.
public interface MyListener() {
void myMethod(SubClass e);
}
When I use the old-school Java 7 style:
addListener(new MyListener() {
@Override
public void myMethod(SubClass e) {
System.out.println(e);
}
});
everything works fine!
If I use Java 8 lambda expression instead:
addListener(e -> {
System.out.println(e);
});
it will throw an exception:
java.lang.IllegalAccessError: tried to access class SuperClass
I wonder if this is a documented shortcoming of Java 8 lambda expressions or a bug?
Can somebody help here?