是否可以在Java 8中调试Lambdas [英] Is it possible to debug Lambdas in Java 8
问题描述
我刚刚开始玩Java 8 Lambdas,我注意到我无法在NetBeans IDE中调试它们。如果我尝试附加一个断点到以下代码,我得到一个可变的断点,这绝对不是我想要的:
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将调试器附加到myListener变量,但我无法进入EventListener本身我看不到其中发生了什么。
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.
是否有调试信息丢失,这是NetBeans中缺少的功能,还是无法调试Lambdas Java?
Is there debugging information missing, is this a missing feature in NetBeans or is it not at all possible to debug Lambdas in Java?
推荐答案
它在Eclipse中适用于我。例如:
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();
}
}
我可以在$ $中的各个行添加断点c $ c> r1 和 r2
,并按步骤等进行适当的打击。
I can add breakpoints to individual lines within both r1
and r2
, and they get hit appropriately, with stepping etc.
如果我只在 run()
调用中放置一个断点,那么我也可以将进入相关的lambda表达式。
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.
编辑:显然上面的工作在Netbeans - 我建议你尝试检查你可以让它工作。
Apparently the above works in Netbeans too - I suggest you try it to check that you can get that working.
这篇关于是否可以在Java 8中调试Lambdas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!