非线性条件断点 [英] Non-line dependent conditional breakpoints
问题描述
是否可以设置断点,以便程序在指令达到某些条件后才停止执行?
Is it possible to set a breakpoint so that the program stops executing after an instruction has made certain condition true
?
一个类有一个名为 currency
的变量,我想做一个断点,使程序在 currency == 20
。我不知道货币
改变的行号,所以这就像在我的班级的每一行中放置一个断点。其中货币
已更改]。
A class has a variable named currency
and I want to make a breakpoint to make the program stop at any line after currency == 20
. I do not know the line number where currency
is changed, so this would be like putting a breakpoint in every line of my class [ed. where currency
gets changed].
有没有办法完成(除了在每一行添加断点) ?
Is there any way to accomplish that (besides adding a breakpoint at each line)?
我正在使用NetBeans,但欢迎任何其他IDE中的解决方案。
I am using NetBeans, but a solution in any other IDE is welcome.
推荐答案
更改您编写软件的方式。
Change the way you write software.
而不是:
public class BreakEncapsulation {
private float currency = 0.0;
public BreakEncapsluation() {
this.currency += 5;
}
public void updateCurrency() {
this.currency = 20.0;
}
public void increaseCurrencyByRate() {
this.currency += 2;
}
public void decreaseCurrencyByRate() {
this.currency -= 2;
}
}
执行此操作:
public class HonourEncapsulation {
private float currency;
public HonourEncapsluation() {
setCurrency( getCurrency() + 5 );
}
public void updateCurrency() {
setCurrency( 20.0 );
}
public void increaseCurrencyByRate() {
setCurrency( getCurrency() + getRate() );
}
public void decreaseCurrencyByRate() {
setCurrency( getCurrency() - getRate() );
}
public void setCurrency( float currency ) {
System.out.println( "Old currency = " + this.currency );
// Set the break point here. This is the only spot in the entire system
// where the value of currency changes. This idea follows the DRY
// principle: every piece of information should have exactly one
// occurrence.
//
this.currency = currency;
System.out.println( "New currency = " + this.currency );
}
private float getCurrency() { return this.currency; }
private float getRate() { return 2.0; }
}
这不仅有助于维护代码(没有代码重复)它保持了一个可能性开放的世界。这可能无法帮助您解决当前的问题,但这将有助于您避免将来出现的一些问题。
Not only does this help with maintaining your code (no code duplication), it keeps a world of possibilities open. It might not help you with your current issue, but it will help you avoid a number of problems in the future.
这是一种称为 em>,并且与信息隐藏密切相关。
This is a technique called encapsulation, and is closely related to information hiding.
这篇关于非线性条件断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!