在Java中如何使用watch表达式进行调试(通过具体示例)?
您能帮助我理解在Java中如何使用Watch进行调试吗?在下面的评论中,我捕获了“监视”窗口中显示的值。 需要讨论的几个前期问题:在Java中如何使用watch表达式进行调试(通过具体示例)?,java,debugging,constructor,watch,Java,Debugging,Constructor,Watch,您能帮助我理解在Java中如何使用Watch进行调试吗?在下面的评论中,我捕获了“监视”窗口中显示的值。 需要讨论的几个前期问题: 这个符号是什么意思,例如:“73” 当调用newtest(t2)来创建下一个对象时,t1=t2(正如构造函数所建议的)。在这个上下文中,t1是每个测试实例变量所具有的属性t1吗 测试对象(t1)的属性能否等于测试对象(t2)?在这种情况下,这是否意味着它们指向相同的对象,因此它们存储相同的地址 为什么#73是t3.t1的值?是因为在使用参数运行构造函数之后t1=t2
class Test {
Test t1;
Test() {}
Test (Test t) {
t1=t;
}
public static void main (String[] args)
{
Test t2 = new Test(); // t2 #73 ; t2.t1 null ; t1 = cannot access instance variable from static context
Test t3 = new Test(t2); // t3 #74 ; t3.t1 #73 ; t1 = cannot access instance variable from static context
t3.go(); // prints "hi"
Test t4 = t3.t1; // t4 #73 ; t4.t1 null
t4.go(); // prints "hi"
Test t5 = t2.t1; // t5 null
t5.go(); // NullPointerException (is it because a null object can't invoke any method?)
}
void go() { System.out.println("hi");
}
}
PS:使用Netbeans,我按照以下步骤调试和显示手表:
- 右键单击并在代码行上设置断点
- 按住Ctrl+Shift+F5键以调试文件
- 进入(F7)
- 跨步表达式(F8)