Why I cannot put a breakpoint on line String a;?
public void localMethod() {
String a;
a = "haha";
System.out.println(a);
}
I know local variable will not be initialized until I assign a value to it explicitly.
But it is a line of code, it does something. Why I cannot stop there?
What lines are eligible to be breakpoints?
I am using Eclipse, jdk6_31
The declaration itself isn’t really executable code – it’s just declaring the existence of something. You should be able to put a breakpoint on the second line, which actually does something.
Admittedly I don’t see any reason why an IDE shouldn’t support the notion of adding a breakpoint to a non-executable line – it would probably have to really install the breakpoint at an executable point within the executing environment…
EDIT: To clarify what I mean, this code:
will compile to the same bytecode as:
No code has to execute due to a declaration – it doesn’t reserve space at that point in time or anything like that. The compiler allocates a “slot” within the method’s stack space, and will use that slot throughout the method – but it can reuse that same slot with no extra initialization even if the variable is declared within a loop, for example.