Is it possible to debug Lambdas in Java 8

I just started playing with Java 8 Lambdas and I noticed that I can't debug them in the NetBeans IDE. If I try to attach a breakpoint to the following code I get a variable breakpoint which is definately not what I wanted:

private EventListener myListener (Event event) ->
{
  command1;
  command2; // Set Breakpoint here
  command3;
};

NetBeans attaches the debugger at the "myListener" variable but I can't step into the EventListener itself so I can't see what is happening inside it.

Is there debugging information missing, is this a missing feature in NetBeans or is it not at all possible to debug Lambdas in Java?

Jon Skeet
people
quotationmark

It works for me in Eclipse. For example:

public class Foo {

    private static final Runnable r1 = () -> {
        System.out.println("r1a");
        System.out.println("r1b");
    };

    public static void main(String[] args) {
        Runnable r2 = () -> {
            System.out.println("r2a");
            System.out.println("r2b");
        };

        r1.run();
        r2.run();
    }
}

I can add breakpoints to individual lines within both r1 and r2, and they get hit appropriately, with stepping etc.

If I put a breakpoint on just the run() calls, I can step into the relevant lambda expression too.

So it sounds like all the debug information at least can be available.

EDIT: Apparently the above works in Netbeans too - I suggest you try it to check that you can get that working.

people

See more on this question at Stackoverflow