Reputation: 26084
Say I have below code:
Shape shape;
shape = new Circle();
When debugging using breakpoints, I'm wondering why is not possible to stop execution in the first line. I know it's quite useless, but it's a valid statement right? It's allocating memory for reference variable...
Upvotes: 1
Views: 307
Reputation: 2490
I know it's quite useless, but it's a valid statement right?
Technically it's not a statement. It's a variable declaration and those are not statements.
Though admittedly, when a declaration also initializes the variable's value, counting it as not a statement is not very helpful, so while it's still not called a statement in that case you can put a breakpoint.
It's allocating memory for reference variable...
Nope. When local variables need to be stored, they're stored on the stack, or whatever mechanism the underlying platform implements the stack functionality with. This requires no allocation. Therefore, the line is a no-op. It's information that only do stuff for the compiler, and doesn't exist at runtime.
Upvotes: 2
Reputation: 1521
The problem is that while the compiler conceptually ‘reserves space’ for the reference on the first line, it only needs to ‘do something’ on the second line, so there’s only code there, so later, when you’re trying to set the breakpoint, it’s only possible on the code, I.e. the 2nd line.
Upvotes: 1
Reputation: 593
You can set a breakpoint on any line of executable code .The declaration itself (Shape shape;
) isn't really executable code
Upvotes: 1